-1

the below is the script i have written, by using below code i am getting error message properly but, if i enter the field the error message still be displaying any idea how to clear the error message.

var flag=0
     function otpValidate()
     (
         otp=oneTimePass.onetimepass.value
         if(otp=="")
         (
             document.getElementById('error0').innerHTML="Enter one time password"
             flag=1;
         )else if(otp.length != 6)
         (
             document.getElementById('error0').innerHTML="PIN must be 6 digits"
             flag=1
         )
     )   
     function check(form)
 (
     flag==0
     otpValidate()
     if(flag=1)
         return false

     else
         return true
 )

1 Answers1

3

You have many errors.

if(flag=1) is not a condition but an allocation. Write if(flag==1) instead.

Replace function otpValidate() (... ) to function otpValidate() {... }.

It's the same for if statement. Replace if() (...) by if() {...}

Note : At the end line you should add ; in javascript


Code without mistake :

var flag = 0;
function otpValidate() {
     otp = oneTimePass.onetimepass.value;
     if(otp == "") {
         document.getElementById('error0').innerHTML = "Enter one time password";
         flag = 1;
     } else if(otp.length != 6) { 
         document.getElementById('error0').innerHTML = "PIN must be 6 digits";
         flag = 1;
     }
 }  
 function check(form) {
     flag = 0;
     otpValidate();
     if (flag == 1)
         return false;
     else
         return true;
 }
R3tep
  • 12,512
  • 10
  • 48
  • 75
  • i did that because i was not able to post i jus tried putting single equal sign n i am able to post it . that was not error in my code ... – sharad harpanahalli Sep 28 '15 at 14:33
  • just remove my name, and rewrite his code without mistake – Sherali Turdiyev Sep 28 '15 at 14:36
  • JavaScript actually doesn't require a ; at the end of lines: http://mislav.uniqpath.com/2010/05/semicolons/ – Joseph Duty Sep 28 '15 at 15:01
  • bcoz stack over flow was not allowing me to post this code so i removed the braces and i have added brackets. the code above is my proper code but m not able to clear the error message after entering the field. help me out its urgent. – sharad harpanahalli Sep 28 '15 at 15:22