Jump to content

send a php string to javascript


Vitamin

Recommended Posts

I'm not sure if this is a javascript or php question so I'm just posting it here.

I'm trying to send a php variable to java script.  I can't get it to work.

 

function mapchange(chosen, mapnames) {
    var box1 = document.filter.map
    if (chosen == '1') {
        box1.options.length = 0;
        box1.options[box1.options.length] = new Option('first choice - option one','oneone');
    }
}

 

echo '<tr><td><input type="radio" name="gametype" value="1v1" onClick="toggle1v1()" onChange="mapchange(1,' . $test . ')" />1v1</td>';

 

The combo box in this test should just be recreated with just 'first choice - option one' displayed in it.

If I remove the $test from the php it works fine.  Any ideas?

Link to comment
Share on other sites

HAHA Thank you kind sir.

 

I have been just using the string 'hi' for testing, but now when I create the real string that I am sending that has a (') within the string how do I escape that?

 

The string that I am creating is being pulled from a database.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.