0

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.

2 Answers 2

1

Change

<form id ="myform" onSubit="return validatefields()" >

To

 <form id ="myform" onsubmit="return validatefields()" >
  1. Case (onsubmit) is not really important, but spelling is... (#2 deleted after remark from @shad)
Sign up to request clarification or add additional context in comments.

2 Comments

@Shad, indeed you are correct. I was sure I had done it without the 'return'.
That was a typing type but in actual code its onsubmit.Thanks for answering me.
0

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
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.