jquery: how to remove blank fields from a form before submitting?

One way would be to set the “disabled” attribute on those fields, which prevents their values from being serialized and sent to the server: $(function() { $(“form”).submit(function() { $(this).children(‘:input[value=””]’).attr(“disabled”, “disabled”); return true; // ensure form still submits }); }); If you have client-side validation, you’ll also want to re-enable these fields in the event of … Read more

Bypass HTML “required” attribute when submitting [duplicate]

No JavaScript, no second form needed, and the validation can stay: For exactly this use case the HTML5 spec has designed the formnovalidate attribute for submit elements (like <input type=submit>), as one of the attributes for form submission: The formnovalidate attribute can be used to make submit buttons that do not trigger the constraint validation. … Read more

why doesn’t hitting enter when a SELECT is focused submit the form?

It’s simply the nature of the control. The Enter key (or a mouse click) is what makes the selection. To submit the form when pressing Enter would result in a poor user experience, since the form would essentially be unusable. I would not recommend changing the behavior via JavaScript, simply because the default behavior is … Read more

How to capture submit event using jQuery in an ASP.NET application?

Thanks, @Ken Browning and @russau for pointing me in the direction of hijacking __doPostBack. I’ve seen a couple of different approaches to this: Hard-code my own version of __doPostBack, and put it later on the page so that it overwrites the standard one. Overload Render on the page and inject my own custom code into … Read more

AngularJS: Call the ng-submit event outside the form

Use HTML5’s form attribute, here’s a sample: angular.module(‘app’, []) .controller(‘MyCtrl’, [‘$scope’, function($scope) { $scope.submitted = false; $scope.confirm = function() { $scope.submitted = true; }; }]); form { padding:5px; border: 1px solid black } <!DOCTYPE html> <html ng-app=”app”> <head> <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js”></script> <meta charset=”utf-8″> <title>JS Bin</title> </head> <body ng-controller=”MyCtrl”> <form id=”myform” ng-submit=”confirm()”> <label for=”myinput”>My Input</label> <input type=”text” … Read more

Javascript Submit does not include Submit Button Value

Yes, that is the correct behavior of HTMLFormElement.submit() The reason your submit button value isn’t sent is because HTML forms are designed so that they send the value of the submit button that was clicked (or otherwise activated). This allows for multiple submit buttons per form, such as a scenario where you’d want both “Preview” … Read more

MVC jQuery submit form (without page refresh) from JavaScript function

This is how I do that with jquery: function DoAjaxPostAndMore(btnClicked) { var $form = $(btnClicked).parents(‘form’); $.ajax({ type: “POST”, url: $form.attr(‘action’), data: $form.serialize(), error: function(xhr, status, error) { //do something about the error }, success: function(response) { //do something with response LoadBooks(); } }); return false;// if it’s a link to prevent post } I assumed … Read more