Daily Technology News, Tips, and Reviews | Subscribe to Jason Slater Technology BlogTechnology Feed | Join Jason Slater on TwitterTwitter | Thursday 2nd September 2010

Javascript: Set Focus of HTML Textbox

By Jason Slater
  • DiggThis
  • Share

To set the focus of a HTML text box include this short piece of code in the <head> section

<script>function setfoc() { document.f1.KeyWords.focus(); }

In the example above f1 is the name of the form and KeyWords is the name of the input textbox

In the body section:

<form name="f1" action="youraction" method="POST">
<input type="text" name="KeyWords" size="40" value="default text">
</form>

<script language="JavaScript">setfoc();</script>

Related

One comment so far

  • [...] tagged javascriptOwn a WordPress blog? Make monetization easier with the WP Affiliate Pro plugin. Javascript: Set Focus of HTML Textbox saved by 2 others     XzxJaNxzX bookmarked on 05/24/08 | [...]

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.