Created
June 15, 2015 20:44
-
-
Save javierguerrero/3d1a5e7ce3959692e041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="hidden_form_container" style="display:none;"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function postRefreshPage () { | |
var theForm, newInput1, newInput2; | |
// Start by creating a <form> | |
theForm = document.createElement('form'); | |
theForm.action = 'somepage.php'; | |
theForm.method = 'post'; | |
// Next create the <input>s in the form and give them names and values | |
newInput1 = document.createElement('input'); | |
newInput1.type = 'hidden'; | |
newInput1.name = 'input_1'; | |
newInput1.value = 'value 1'; | |
newInput2 = document.createElement('input'); | |
newInput2.type = 'hidden'; | |
newInput2.name = 'input_2'; | |
newInput2.value = 'value 2'; | |
// Now put everything together... | |
theForm.appendChild(newInput1); | |
theForm.appendChild(newInput2); | |
// ...and it to the DOM... | |
document.getElementById('hidden_form_container').appendChild(theForm); | |
// ...and submit it | |
theForm.submit(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--This is equivalent to submitting this HTML form:--> | |
<form action="somepage.php" method="post"> | |
<input type="hidden" name="input_1" value="value 1" /> | |
<input type="hidden" name="input_2" value="value 2" /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment