Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    passing a form variable to a url variable

    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.

    Code:
    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.
    Last edited by Bobafart; 07-13-2007 at 04:40 PM. Reason: spelling

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •