0
<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.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Teejaygenius
  • 49
  • 1
  • 1
  • 6
  • possible duplicate of [Pass a PHP string to a Javascript variable (including escaping newlines)](http://stackoverflow.com/questions/168214/pass-a-php-string-to-a-javascript-variable-including-escaping-newlines) – Felix Kling Jan 05 '12 at 16:16

2 Answers2

2
<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

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
1

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']; ?>')
Paul
  • 139,544
  • 27
  • 275
  • 264
  • @Teejaygenius In that case the error most likely occurs with the `$` n the name: http://www.w3.org/TR/html4/types.html#type-cdata – Paul Jan 05 '12 at 17:07
  • @Teejaygenius """ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").""", so starting a name with `$` is invalid markup and undefined behaviour, which means your `$_POST` might not fill correctly with it. You can check your `$_POST` for `$qtnid` with `print_r($_POST)` – Paul Jan 05 '12 at 17:09