PDA

View Full Version : Javascript Control Php Display



bluewalrus
09-15-2009, 03:59 PM
Is there a way to have a javascript value control which php is displayed? For example I'm trying to use an increasing javascript variable to control which php array value is displayed.



var x = 0;
while ( x < <?php echo $Total; ?> ) {
var address = "<?php echo $Name[?>x<?php ];?>>";
x++;
}


So it would go be to the php as something like this in the end



var x = 0;
// x=0
while ( 0 < 5 ) {
var address = "<?php echo $Name[0];?>";
x++;

//x = 1
var address = "<?php echo $Name[1];?>";
x++;
// ETC.
}


and on the actual page



var x = 0;
// x=0
while ( 0 < 5 ) {
var address = "22 main street city, state, country";
x++;

//x = 1
var address = "23 different street city, state, country";
x++;
// ETC.
}

thenajsays
09-15-2009, 05:02 PM
yup... i believe all you need to do is save the file with a PHP extension as opposed to HTML (or JS) and then it should work... i did something similar to this on a contact form... theres an ajax thank you message that i wanted to be editable via the content management database, so i used that little trick...
Second Link is the one you want (http://lmgtfy.com/?q=write+javascript+with+php)

bluewalrus
09-16-2009, 08:28 PM
I actually had to go about creating the same process in php that I did in javascript so the page wouldnt have to be reloaded again as the php was being processed first.