Jquery Before Submitting The Form
I have a list, (a simple list) from which i am able to select and set elements (using js), and then a form that allows me to choose how many elements i want, and a submit form.if o
Solution 1:
Add a submit
listener to the form. When it's submitted, check to see if an element is selected, and if not you can prevent the submission by using return false
. Here's an example:
$('#myForm').submit(function()
{
if (/* test case not true */) {
$('#myError').show();
returnfalse;
}
// ... continue work
});
And here's the HTML:
<form id="myForm">
<input type="text"/>
<input type="submit"/>
</form>
If you don't want to use jQuery, you can also handle the submit event with plain JavaScript like so:
var myform = document.getElementById('myForm');
myform.addEventListener('submit', function() { console.log('Submitted!'); returnfalse; });
Post a Comment for "Jquery Before Submitting The Form"