Sorry for asking many questions, My doubt is:
<form id ="myform" onSubit="return validatefields()" >
all fields(for some of them I have same class, so need to validates all the elements having the same class)
function validatefields(){
$(".someclass").each(function(index) {
//some validation
});
}
I am not sure if this is开发者_如何转开发 the valid syntax. Can anyone help me with the syntax.
Change
<form id ="myform" onSubit="return validatefields()" >
To
<form id ="myform" onsubmit="return validatefields()" >
- Case (onsubmit) is not really important, but spelling is... (#2 deleted after remark from @shad)
you should return a value so that the form will know whether to continue or not.
function validatefields(){
var valid = false; //set to true if all inputs validated
$(".someclass").each(function(index) {
//some validation
//if valid:
valid = true;
});
return valid; //if this returns false, the script will stop, else it will submit
}
精彩评论