Hi, I am trying to post a javascript variable as form input to a php file. I have a radio button and if the user selects the radio button and submits the form,the javascript variable should be posted to the php file.However,it is not working.This is what I am trying to do.What's the correct method?Thanks Note:questions[4][1] is the javascript variable here. <input type="radio" name="q5"><script>document.write(questions[4][1]);</script><br>
Assuming myVariable is global: <input type="radio" name="q5" onclick='this.value=myVariable'> Code (markup): There should be more than one button in the group, otherwise the action cannot be undone. Perhaps: <input type="radio" name="q5" onclick='q5[1].value=null'>Undo<br> <input type="radio" name="q5" onclick='this.value=myVariable'>Set Code (markup):
yeah, there will be more than one radio button.This is how the form looks like <form name="QuestionAnswers" action="30" method= "post"> <input type="submit" name="Submit_answers" value="Submit Answers" > <script>document.write(questions[0][0]);</script><br> <!-- This is the question --> <!-- The following are the answer choices --> <input type="radio" name="q1"><script>document.write(questions[0][1]);</script><br> <input type="radio" name="q1"><script>document.write(questions[0][2]);</script><br> </form> Code (markup):
Hi Your method worked.Thanks a lot.Here's my new code(please note that I have not published certain parts of the code before/after and in between the present code as I thought it was irrelevant to the discussion.) <form name="QuestionAnswers" action="30" method= "post"> <input type="submit" name="Submit_answers" value="Submit Answers" > <!--This is the question--> <script>document.write(questions[0][0]);</script><br> <!--These are the answer choices--> <input type="radio" name="q1" onclick='this.value=questions[0][1]'><script>document.write(questions[0][1]);</script><br> <input type="radio" name="q1" onclick='this.value=questions[0][2]'><script>document.write(questions[0][2]);</script><br> </form> Code (markup):