Skip to content Skip to sidebar Skip to footer

Submit A Post Variable With Javascript?

Is there anyway to submit a POST variable, with name, to another page? I.e. form submission, as IF a button were clicked, but without having to click a button.

Solution 1:

There are many ways to do this - the easiest, library-free method probably being something like:

If your HTML looks like this (has at least the id, method, and action attributes)

<form id="myForm" method="post" action="post-target.php">
   <input type="hidden" name="username" value="username" />
</form>

You can submit the form via javascript like this:

myForm = document.getElementById('myForm');
myForm.submit();

Solution 2:

Yes: you could for example use jQuery to tie a JavaScript function to a button's onclick event. And then call the click() function on the button in the jQuery ready function.

Post a Comment for "Submit A Post Variable With Javascript?"