View Full Version : PHP vars getting set in JS section

08-02-2008, 04:24 AM
I am trying to initialize a PHP variable inside my JS section of my form. Although I am runnng Firefox, the var 'php_category_cbo_width' is getting set inside the opera if statement below. This does not make any sense to me - I thought I could set some PHP vars in the JS section and use if statements to control when and if a php var gets set? But my debugging shows me when m form executes, the 'php_category_cbo_width' value is 14 and 16 as intended.

if ($.browser.name == 'firefox')
$_SESSION['php_category_cbo_width'] = 16;
document.getElementById('record_textarea').rows = 20;
if ($.browser.name == 'opera')
$_SESSION['php_category_cbo_width'] = 14;
document.getElementById('cat_cbo').size = 9;

08-02-2008, 04:36 AM
PHP code on a page is execuited on the server when the page is requested.

08-02-2008, 05:34 AM
What CFMaBiSmAd said. See, when that page is loaded, the server parses that PHP code and sends it to the user...it doesn't check the Javascript to see which PHP code to parse...it does it all at once. So in your example, the server first sets $_SESSION['php_category_cbo_width'] to 16 and then moves on to the next and sets it to 14, since it doesn't look at Javascript.

08-02-2008, 11:49 PM
and on that note you not outputing any thing you can do stuff like this with javascript and php

var mytest = <?php echo $myvar; ?> ;