Created
October 11, 2019 03:55
-
-
Save junaidtk/22e03c28a44d756faa34895c0c007a5f to your computer and use it in GitHub Desktop.
jQuery submit() doesn't include its value.
This file contains hidden or 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
If we are using the button in the form for submitting the data, then it will work if we click the button. | |
If we are using the jQuery.submit() function for submiting the form. Then the button value doesn't submit. | |
For working form with the button value without an issue you just need to configure the a hidden input | |
and add all the button property to the hidden field. | |
Below is the code for configuring the form. | |
$("input[type=submit], input[type=button], button").click(function(e) { | |
var self= $(this), | |
form = self.closest(form), | |
tempElement = $("<input type='hidden'/>"); | |
// clone the important parts of the button used to submit the form. | |
tempElement | |
.attr("name", this.name) | |
.val(self.val()) | |
.appendTo(form); | |
// boom shakalaka! | |
form.submit(); | |
// we don't want our temp element cluttering up the DOM, do we? | |
tempElement.remove(); | |
// prevent default since we are already submitting the button's form. | |
e.preventDefault(); | |
}); | |
So while submitting the form configure a hidden field. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment