...

View Full Version : Adding focus to first form field without using body onload..



AshleyQuick
02-12-2004, 07:48 PM
Is this possible?

Choopernickel
02-12-2004, 07:54 PM
Of course. Use window.onload .


window.onload = document.forms[0].elements[0].focus;

AshleyQuick
02-12-2004, 08:00 PM
So I place that in my js file. What must I add here? (which is the 1st field)

<input type="text" maxlength="65">

AshleyQuick
02-12-2004, 08:19 PM
Nevermind, got it working with:

function setFocus() {
document.forms[0].elements[0].focus;
}
window.onload=setFocus;

Garadon
02-12-2004, 08:29 PM
<form name=test1>
<input type=text name="test">
</form><script>
document.forms['test1'].elements['test'].focus();</script>

glenngv
02-13-2004, 02:24 AM
Originally posted by AshleyQuick
Nevermind, got it working with:

function setFocus() {
document.forms[0].elements[0].focus;
}
window.onload=setFocus;

function setFocus() {
document.forms[0].elements[0].focus();
}

Shorter version:

window.onload=function(){document.forms[0].elements[0].focus();}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum