GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   little php help (https://gfy.com/showthread.php?t=934105)

fris 10-19-2009 09:57 AM

little php help
 
how do I declare a variable in php to use in javascript

Code:

function msnad_head() {
    $siteurl = get_option('siteurl');
    $url = $siteurl . '/wp-content/plugins/' . basename(dirname(__FILE__)) . '/msnad.js';

    print('
<script type="text/javascript">
    var linkout="http://www.google.com";
    var maintxt = $msnad_settings['message']; //this part
    var toptext="New Instant Message:";
    var imgad="impic.jpg";
</script>
<script type="text/javascript" src="'.$url.'"></script>

    ');
}


sexy-frenchie 10-19-2009 10:06 AM

Try this:

PHP Code:

echo '
<script type="text/javascript">
    var linkout="http://www.google.com";
    var maintxt = "' 
$msnad_settings['message'] . '";
    var toptext="New Instant Message:";
    var imgad="impic.jpg";
</script>
<script type="text/javascript" src="'
.$url.'"></script>
'



fris 10-19-2009 10:18 AM

result is blank

var maintxt = "";

is its output

sexy-frenchie 10-19-2009 10:24 AM

The array $msnad_settings is not defined in your function.
Where does its value come from?

calmlikeabomb 10-19-2009 10:48 AM

Right, $msnad_settings is out of scope.

You'll either need to give it some kind of global scope such as assigning it to a $_SESSION variable, or pass it to your function.

fris 10-19-2009 10:50 AM

ya works now forgot to global $msnad_settings;

Killswitch - BANNED FOR LIFE 10-19-2009 12:35 PM

Darrrrrrrrr.


All times are GMT -7. The time now is 07:53 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc