How to create auto focus in JavaScript validation

<!--DOCTYPE html--> <html> <head> <title></title> <script> function validatee(){ // 1st Method if(document.forms['frm']['nm'].value == ""){ alert( "Please provide your name!" ); document.forms['frm']['nm'].focus() ; return false; } // 2nd Method /* nmm=document.forms['frm']['nm']; if(nmm.value== ""){ alert( "Please provide your name!" ); nmm.focus(); return false; } */ if (num=document.forms['frm']['noss'].value==""){ document.getElementById("numl").innerHTML="Fill this field"; return false; }else{ return true; } // Number Validation /*var num=document.forms['frm']['noss'].value; //document.getElementById("nameloc").innerHTML=" <img src='checked.gif'/>"; if (isNaN(num)){ document.getElementById("numl").innerHTML="Enter Numeric value only"; return false; }else{ return true; } */ } </script> </head> <body> <div class="fcss"> <form name="frm" onsubmit="return validatee()"> <table border="1"> <tr> <td><input type="text" name="nm" placeholder="Name"></td> </tr> <tr> <td><input type="text" name="noss" placeholder="Mobile"><span id="numl"></span></td> </tr> <tr> <td><input type="submit"></td> </tr> </table> </form> </div> </body> </html>

agyanadda

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 $type={blogger}:

Post a Comment