...

View Full Version : passing a form variable to a url variable



Bobafart
07-13-2007, 04:39 PM
Hello.

I am trying to pass a form variable into a url variable which is used in a seperate script.

Script 1: the form

an option/select menu stores a character string value in a variable called "troopSquad"

Script 2: the JS function

the form submits to this script which has a JS AJAX function which references a server side script which requires the value of the variable troopSquad.




function blahblah(){

var troopSquad = <?php echo $troopSquad; ?>;

var sUrl = "php/doCombat.php?attackType=" + attackType + "&amtDmgDBColumn=" + amtDmgDBColumn + "&troopSquad=" + troopSquad;

...
}


this gives me an error:

illegal character
var troopSquad = \'two\';\n

how would you solve this problem? perhaps I am going about this the wrong way.

glenngv
07-13-2007, 05:25 PM
var troopSquad = '<?php echo $troopSquad; ?>';
If you use double quotes as string delimiter, make sure that double quotes are also escaped in the $troopSquad variable as you did in single quotes.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum