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
https://forums.phpfreaks.com/topic/216624-send-a-php-string-to-javascript/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.