• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

urgent help needed: passing php variables to javascript

eon

2[H]4U
Joined
Oct 11, 2003
Messages
2,218
I'm trying to loop through a php array in javascript to run them into a function but the $counter variable does not want to get incremented no matter what I do.

Code:
**inside of javascript
	var jsize = <? echo $size; ?>;	
	for(var i = 0; i < jsize; i++)
	{
	  var y = <? echo $la[$counter]; ?>;
	  var x = <? echo $lo[$counter]; ?>;
	  var latlng = new GLatLng(y, x);
	  <? $counter = $counter + 1; ?>
          map.addOverlay(createMarker(latlng, i));
	}
**/end of javascript
 
So you want your JS to increment a PHP variable? Dear God, please tell me you're joking.
 
well its incremented in php
if you know a better way (already tried like 5 different methods) please let me know
 
why not just use the value of $i instead of $counter?

also, stick an alert inside the for loop to make sure you actually landing in there
 
Sure man, I'm going to read your mind and figure out what you want to do. Give me a second... No wait, I forgot I lost my telepathic abilities last week.
 
You are not able to modify a PHP variable using Javascript. Unless the java script is part of a larger PHP script:

PHP:
for($counter=0;$counter < $some_value; $counter++)
{
**inside of javascript
var jsize = <? echo $size; ?>;
for(var i = 0; i < jsize; i++)
{
var y = <? echo $la[$counter]; ?>;
var x = <? echo $lo[$counter]; ?>;
var latlng = new GLatLng(y, x);
<? $counter = $counter + 1; ?>
map.addOverlay(createMarker(latlng, i));
}
**/end of javascript

PHP:
}

Or you make AJAX calls to update a $_SESSION variable.

Though, I am not sure what you want to do. Could you give some more detail?
 
Back
Top