Teejaygenius
Teejaygenius

Reputation: 49

Send php variable into javascript

<input type="button" name="Next" id="Next" value="Next" onclick="showNextQuest(<?php echo $_POST  ['$qtnid']; ?>)" />

$qtnid is the name of a radio button, i used the post method to know which one among the radio buttons is selected. The radio button has the same name with different values.It return an undefined error when itried to use alert function inside the showNextQuest function in the javascript. plz help me out.

Upvotes: 0

Views: 81

Answers (2)

Eugen Rieck
Eugen Rieck

Reputation: 65342

<input type="button" name="Next" id="Next" value="Next" onclick="showNextQuest(<?php echo $_POST  ['$qtnid']; ?>)" />

should be

<input type="button" name="Next" id="Next" value="Next" onclick="showNextQuest('<?php echo $_POST  ['$qtnid']; ?>')" />

To make it a string, not a varname

Upvotes: 2

Paul
Paul

Reputation: 141937

If the values are strings you should also put single quotes around your PHP if you want to pass the value as a string:

showNextQuest('<?php echo $_POST['$qtnid']; ?>')

Upvotes: 1

Related Questions