jquery - How do I stop a form from submitting? -


this question has answer here:

how stop form submitting? have validation on form, , if the input isn't correct, form should't submit... in html have when clicking submit:

<a href="#" onclick="settimeout(function(){document.getelementbyid('form_4').submit()}, 1000);" style="position:static" class="btn-more">vælg</a> 

and script looks this:

$("#form_4 a.btn-more").click(function (e) {      //validate required fields     (i = 0; < required.length; i++) {         var input = $('#' + required[i]);          if ((input.val() == "") || (input.val() == emptyerror)) {             input.addclass("needsfilled");             input.val(emptyerror);             errornotice.fadein(750);             e.stoppropagation();             return false;         } else {             input.removeclass("needsfilled");         }     }     //if inputs on page have class 'needsfilled' form not submit     if ($(":input").hasclass("needsfilled")) {         return false;     } else {         errornotice.hide();         return true;     } }); 

use :

e.preventdefault();   

before closing click function or @ start

$("#form_4 a.btn-more").click(function(e){       e.preventdefault();       //rest of content } 

you should change settimeout function way have done it, submit form. change :

html :

<a href="#" style="position:static" class="btn-more">vælg</a> 

script :

$("#form_4 a.btn-more").click(function (e) {      //validate required fields     (i = 0; < required.length; i++) {         var input = $('#' + required[i]);          if ((input.val() == "") || (input.val() == emptyerror)) {             input.addclass("needsfilled");             input.val(emptyerror);             errornotice.fadein(750);             e.stoppropagation();             return false;         } else {             input.removeclass("needsfilled");         }     }     //if inputs on page have class 'needsfilled' form not submit     if ($(":input").hasclass("needsfilled")) {         e.preventdefault();           return false;     } else {         errornotice.hide();         return true;     } }); 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -