Search Engine Optimization > Web Development > Forms: making one field the default for cursor focus
Forms: making one field the default for cursor focus
Posted by Martin Underwood on February 5th, 2006

Is there a way on a form of making one field the default field such that as
soon as you navigate to the form page, the cursor is sitting on that field
ready for data to be entered. I thought that HTML might place the cursor on
the field with the lowest tabindex attribute, but this doesn't appear to be
the case. Instead, it is always necessary to click on the first field, after
which TAB can be used to advance to successive fields.

I'm talking about text fields of the form

<input type="text" size="40" maxlength="256" name="Email" tabindex="4"
style="font-family: Arial">


Posted by Stevie D on February 5th, 2006

Martin Underwood wrote:

In the head, include a bit of javascript:
<script>
<!--
function sf(){document.f.field.focus();}
-->
</script>
then activate it:
<body onLoad="sf()">
And make sure it points to the right place:
<form name="f" ...>
<input name="field" ...>
And bingo!

--
Stevie D
\\\\\ ///// Bringing dating agencies to the
\\\\\\\__X__/////// common hedgehog since 2001 - "HedgeHugs"
___\\\\\\\'/ \'///////_____________________________________________

Funbolt.com - Entertainment portal, wallpapers, sexy celebs