Link Posted February 22, 2008 Share Posted February 22, 2008 How can I gather all the elements of a form in a str of "name1=val1&name2=val2..."? I won't necessarily know the names or number of elements in the form...any clues? Quote Link to comment Share on other sites More sharing options...
phpQuestionerThe4th Posted February 22, 2008 Share Posted February 22, 2008 see how this works out for you: <script language="javascript"> function grabAll() { var theForm = document.getElementsByTagName("input"); for (i=0; i<theForm.length; i++) { var max = theForm.length - 1; if (i == max) { var morestuff=""; } else { var morestuff="&"; } document.getElementById("all").innerHTML += theForm[i].name + "=" + theForm[i].value + morestuff; } } </script> <form> <input type="text" name="name1" value="Bob"> <input type="text" name="name2" value="John"> <input type="text" name="name3" value="Bill"> <input type="text" name="name4" value="Tom"> <input type="text" name="name5" value="Greg"> </form> <br><br> <span id="all"></span> <br><br> <input type="button" name="actionbutton" onclick="grabAll()" value="String'em Together!"> 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.