I was wondering, I have a 2 input submit on my form.
One has a name :
<input name="_close" type="submit" id="myId" value="close">
And when I click on it, i submit the form via (after doing things in JS)
$('#myForm').submit();
Then in my server code I test on the Request if it has the query “_close” but it does not seem to be the case.
My question is :
Is there a way to make the jQuery method .submit() preserve the name of the input button clicked or to manually specify to the .submit() function the extra parameter I want in my next Request ?
Thanks.
Im not sure about submit buttons and how /if they are passed across however if they are not you could in your pre submit javascript assign the value to a hidden input of the same name.
Ive just run an example for you.
test.html
test.php
This does echo Click me to submit
I then did another test using the submit function in jquery which does not pass the value over.
The reason is so that you can test server side which submit button was pressed since you may have more than one submit button on the form. Checking the value allows you to test which one it was specifically that was used to submit the form.
To allow you to use an external input as a particular submit button so that its name/value pair is passed in the request instead of calling
submit()on the form in your jquery, select the submit button itself and callclick()on it. This will tell the form that that particular submit button was used and therefore set its value in the request.