Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery validation form submit

$("#FromId").validate({
  submitHandler: function(form) {
   form.submit();
  }
});
Comment

jquery validation submit handler

$("#myform").validate({
  submitHandler: function(form) {
    $(form).ajaxSubmit();
  }
});
Comment

jquery form validation

function submitFunction(event){
	event.preventDefault();
}
$("#form_id").submit(submitFunction);
Comment

jquery validate submithandler


function submithandler() {
	var errors = [];
	formFields.forEach( (field) => {
    	
        // loop to check all rules attached to the fields
        field.rules.forEach( (rule) => {
        
        	if (rule == 'required' && ! $(`#${field.id}`).val().length) {
            	errors.push(`${field.id} is required!`)
            } else if (rule.includes('max:')) {
            	let limit = rule.split(':')[1]; // this will get the number attached to the max rule
                if (limit > $(`#${field.id}`).val().length ) {
                	errors.push(`maximum length of charater must be `${limit})
                }
            }
        
        })
        
    })
    
    if (errors.length) {
      
     	return errors;
    }
  
  //do ajax post here
  
  
  
}


// edit the code below base on what u need

var formFields = [
	{
    	id:'name', // use to access the dom.eg $('#name')
        rules:['required']
    },
    {
    	id:'phone',
        rules:['required', 'max:11'],
    }
];
Comment

jquery form validation

form validation
Comment

PREVIOUS NEXT
Code Example
Javascript :: string split javascript newline 
Javascript :: converting json to javascript object 
Javascript :: jquery vdn 
Javascript :: react native navigation.navigate with params 
Javascript :: vue print date 
Javascript :: padend method javascript 
Javascript :: committing only some changes to git 
Javascript :: regular expression match text between quotes 
Javascript :: statusbar.sethidden(true) in react native 
Javascript :: toggle attribute jquery 
Javascript :: s3.getobject nodejs example async await 
Javascript :: angular window object 
Javascript :: js wait 
Javascript :: get the value of css properties js 
Javascript :: infinite loop in programming 
Javascript :: get element by multiple class javascript 
Javascript :: how to save cookie in JavaScript 
Javascript :: javascript clear interval 
Javascript :: push only elements list into another list javascript 
Javascript :: setinterval vs settimeout js 
Javascript :: /on in jquery 
Javascript :: how to disable react in jsx scope eslint 
Javascript :: How do I push an element into the array within an object in AngularJS 
Javascript :: drawer navigation set width react native 
Javascript :: javascript seconds to date 
Javascript :: javascript how to raise the error 
Javascript :: replace url without reload js 
Javascript :: update angular materia; 
Javascript :: input length material Ui Design 
Javascript :: remove axis tick ends d3 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =