i have copy and pasted this and it is working perfectly.
but i need to do this for multiple forms on one page.
as you can see i tried to do this by using
<?php echo $form_name; ?>
but since this value is done within a loop it does not work
and here is my htmlCode:<script language="Javascript"> function xmlhttpPost(strURL) { var xmlHttpReq = false; var self = this; // Mozilla/Safari if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); } // IE else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } self.xmlHttpReq.open('POST', strURL, true); self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4) { updatepage(self.xmlHttpReq.responseText); } } self.xmlHttpReq.send(getquerystring()); } function getquerystring() { var form = document.forms['f1']; var formdata = ''; for (i = 0; i < <?php echo $form_name; ?>.elements.length; i++) { // loop through all the form elements formElem = <?php echo $form_name; ?>.elements[i]; switch (formElem.type) { case 'text': case 'hidden': case 'password': case 'textarea': formdata += formElem.name + "=" + escape(formElem.value) + '&'; break; case 'checkbox': case 'radio': if (formElem.checked===true) { formdata += formElem.name + "=" + formElem.value + '&'; } // end of checked box or selected radio button break; case 'select-one': formdata += formElem.name + "=" + escape(formElem.options[formElem.selectedIndex].value) + '&'; break; // it is possible to do this more succinctly, but then it does not work with older browsers default: formdata += formElem.name + "=" + escape(formElem.value) + '&'; // setting a default is all-important } // end switch } // end for loop formdata = formdata.substr(0,(formdata.length -1)); // snip off extra ampersand at the end of the string qstr = formdata ; // NOTE: no '?' before querystring return qstr; } function updatepage(str){ document.getElementById("result").innerHTML = str; } </script>HTML Code:<input type="checkbox" name="sendto" value="true" /> Send a copy to my personal email address <input value="Respond" type="button" onclick='JavaScript:xmlhttpPost("test.php")'> <br/>Once posted can't be edited </form>


Reply With Quote
Bookmarks