Debt Consolidation - Internet Advertising - Debt Consolidation - Debt Consolidation - Debt Consolidation

PDA

View Full Version : To put focus in the first field (form)


piropeator
Apr 15th 2009, 6:11 am
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?

jqueryHowto
Apr 15th 2009, 8:26 am
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();