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? Link to comment https://forums.phpfreaks.com/topic/92403-form-elements/ 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!"> Link to comment https://forums.phpfreaks.com/topic/92403-form-elements/#findComment-473435 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.