I have this code and I want to put focus on the field name, after that put the focus in the last name field and finally the focus will be on OK button. <html> <head> </head> <body> <form name="form" action="process.php" method="post" > <p>Name: <input type="text" name="name"/> <br/> Lastname: <input type="text" name="lastname"/> <br/> <input type="button" value="Return" onClick="javascript:document.location.href='index.php'"/> <input name="submit" type="submit" value="Ok"/> </p> </form> </body> </html> How to do that?
Using jQuery that would be: $('input :first').focus(); or if u wanna be more specific then: $('input[type="text"] :first').focus(); // or $('input[name="name"]').focus();
and maybe he doesn't have jQuery ... just modify the <body> tag to this <body onload="document.form.name.focus();"> Code (markup): and it should work