How to focus cursor on form element?

tashamyq

New Member
I want to add cursor after empty input into form element. Where first empty form are.
With this goal I tryed to add \[code\]this.focus();\[/code\] into \[code\]validate()\[/code\] function. But this wasn't succeeded. And second point - how to set cursor after emerges page at brovser to first form element. I tryed with this target \[code\]onLoad();\[/code\] method into \[code\]body\[/code\]. But this wasn't succeeded.Code:\[code\]<html> <head> <title>Form with check</title> <script> function validate() { if(document.form1.yourname.value.length < 1) { alert("Enter your name, please"); this.focus(); return false; } if(document.form1.adress.value.length < 3) { alert("Enter your adress, please"); this.focus(); return false; } if(document.form1.phone.value.length < 3) { alert("Enter your phone number, please"); this.focus(); return false; } return true; } </script> </head> <body> <h1>Form with check</h1> <p>Input all data. When button Submit pushed data will be sent as message.</p> <form name="form1" action="mailto:[email protected]" enctype="text/plain" onSubmit="validate();"> <p><b>Name:</b><input type="text" length="20" name="yourname"> </p> <p><b>Adress:</b><input type="text" length="20" name="adress"> </p> <p><b>Phone:</b><input type="text" length="20" name="phone"> </p> <input type="SUBMIT" value="http://stackoverflow.com/questions/15874344/Submit"> </form> onLoad(); </body> </html>\[/code\]Question:
  • How to add this functionality to form?
 
Top