/ Published in: JavaScript
This javascript function takes the URL of the target page and an associative array of name/values paires and POSTs the data to the supplied URL by dynamically creating a form and then submitting it.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// POST Function function postwith (to,p) { var myForm = document.createElement("form"); myForm.method="post" ; myForm.action = to ; for (var k in p) { var myInput = document.createElement("input") ; myInput.setAttribute("name", k) ; myInput.setAttribute("value", p[k]); myForm.appendChild(myInput) ; } document.body.appendChild(myForm) ; myForm.submit() ; document.body.removeChild(myForm) ; } // Fire function postwith( 'post.aspx', { user:'peter' , cc:'aus' });
URL: http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-to-post-data-between-pages/