csckid Posted April 16, 2009 Share Posted April 16, 2009 I have created radio option using javascript now how do i submit them Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 16, 2009 Share Posted April 16, 2009 document.forms['formid'].submit(); Quote Link to comment Share on other sites More sharing options...
csckid Posted April 16, 2009 Author Share Posted April 16, 2009 <form method="post" action="thank.php"> number=0; questionno[number] = document.createElement("input"); questionno[number].id = "questionno"+number; questionno[number].name = "questionno"+number; questionno[number].size =2; questionno[number].type = "text"; questionno[number].value= 1+number; <input type="submit" name="save"> </form> now if i click on the submit button and try to get value of isset($_POST['question0']) this returns false any help plz Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 16, 2009 Share Posted April 16, 2009 Perhaps it's because you are creating the field names as "questionno"+number and you are trying to access with the name of $_POST['question0'] Assuming "number" is 0, you should be using $_POST['questionno0'] Quote Link to comment Share on other sites More sharing options...
csckid Posted April 16, 2009 Author Share Posted April 16, 2009 <form name="question" method="post" action="thanks.php"> <input type="button" id="create" value="add" onClick="addquestion()"> <input type="submit" id="savecreate" name="savecreate" value="save"> <script type="text/javascript"> number=0; function addquestion(){ questionno[number] = document.createElement("input"); questionno[number].id = "questionno"+number; questionno[number].name = "questionno"+number; questionno[number].size =2; questionno[number].type = "text"; questionno[number].value= number; } </script> </form> i clicked on submit button and on thanks.php $_POST['questionno0'] was called... no result Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 16, 2009 Share Posted April 16, 2009 Well, there is apparently some details you are leaving out, which makes this more difficult to debug. Based upon the code above I would have to assume there is a gloabl array variable for "questionno". Also the function you have never increases the variable "number" (see note below). Lastly, I don't se anything that actually adds the field to the page! Once I made those changes, it works fine for me. form page <html> <head> <script type="text/javascript"> //Gloabl variables var questionno = new Array(); var number = 0; function addquestion() { //Create the form element questionno[number] = document.createElement("input"); questionno[number].id = "questionno" + number; questionno[number].name = "questionno" + number; questionno[number].size = 2; questionno[number].type = "text"; questionno[number].value = number; //Add form element to page document.getElementById("questionForm").appendChild(questionno[number]); number++; return; } </script> </head> <body> <form name="question" id="questionForm" method="post" action="thanks.php"> <input type="button" id="create" value="add" onClick="addquestion()"> <input type="submit" id="savecreate" name="savecreate" value="save"> </form> </body> </html> thanks.php page <?php echo "<pre>"; print_r($_POST); echo "</pre>"; ?> If I add three fields to the form page the results I get on the thanks.php page are as follows: Array ( [savecreate] => save [questionno0] => 0 [questionno1] => 1 [questionno2] => 2 ) however, it is completely unnecessary to add an index number to every field - and not as efficient. Simply create the fields with a name such that the resulting POST data will be returned as an array variable. (you would need to use an index for the ID values for the fields if you must use that). questionno[number].name = "questionno[]"; Then on the processing page you can access all of the values entered into that group of fields using the variable $_POS['questionno'] which will be an array of all the values. Quote Link to comment Share on other sites More sharing options...
csckid Posted April 16, 2009 Author Share Posted April 16, 2009 thanku it worked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.