Hi,

I have a button:

<input class = "save" type="button" value="Išsaugoti" />

As you can see the type is not submit, it is just button. This is because I want to not allow submission if javascript is disabled.

To submit I run this code:

$('input.save').click(function() {
		
		$('form').attr( 'target', '' );
		$(".edit").validate({
			 
			
			rules: {
			 	input_pavadinimas: {
			      required: true,
			      maxlength: 20
			    },
			    
			    text: {
			    	required: true
			    }
			    
			},
			messages: {
				input_pavadinimas:{
					required: "Neįvedėte pavadinimo",
					maxlength: "Maksimalus ilgis - 20 simbolių"
				},	
				
				text: {
					required: "Neįvedėte teksto"
				}
			}
			
		}
				
		
		);
		
		document.myform.submit();		//myfor - formos name atributas
	});

But the validation doesn't work.

When the button type is submit and I run this code

$(".edit").validate({
		 
		 submitHandler:function(form) {
		
		 form.submit();
		//document.myform.submit();		//myfor - formos name atributas
		 
		 
		
		},
		rules: {
		 	input_pavadinimas: {
		      required: true,
		      maxlength: 20
		    },
		    
		    text: {
		    	required: true
		    }
		    
		},
		messages: {
			input_pavadinimas:{
				required: "Neįvedėte pavadinimo",
				maxlength: "Maksimalus ilgis - 20 simbolių"
			},	
			
			text: {
				required: "Neįvedėte teksto"
			}
		}
		
	});

validation works perfectly.

I don't find in google and in documentation how to run it when button is not submit type :( Can you help me?

Found the solution:

$('input.save').click(function() {
        
        $('form').attr( 'target', '' );
        valid = $(".edit").validate({		
             
            rules: {
                 input_pavadinimas: {
                  required: true,
                  maxlength: 20
                },
                
                text: {
                    required: true
                }
                
            },
            messages: {
                input_pavadinimas:{
                    required: "Neįvedėte pavadinimo",
                    maxlength: "Maksimalus ilgis - 20 simbolių"
                },    
                
                text: {
                    required: "Neįvedėte teksto"
                }
            }
            
        }
                
        
        ).form();
        if(valid)
        	document.myform.submit();
    });
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.