0

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.

Steven Matthews
  • 9,141
  • 40
  • 114
  • 203
  • yes, take a look at this thread: http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit – groffhibbitz Jan 31 '12 at 18:46

2 Answers2

2

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();
Kenan Banks
  • 198,060
  • 33
  • 151
  • 170
  • Yes, but I want the specific information contained in the button to be sent, too. I.e. I want to send a POST variable with the name "del" over to another page. – Steven Matthews Jan 31 '12 at 18:53
0

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.

рüффп
  • 4,865
  • 34
  • 67
  • 109
Sid
  • 7,315
  • 2
  • 26
  • 41