Forum Moderators: open

Message Too Old, No Replies

set focus to a submit button

         

Superbuis1

2:07 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



Hello,

I've tried several things with the focus() function in cooperation with onblur and onload, but I can't get it working. Perhaps this is also a php issue. The thing is that when I enter a certain php page, nothing has the focus. And when I select somewhere in my content page, the button gets the focus (I assume cause it's a submit button). But how can give the button by default the focus, so without clicking on the content page....

Thanks!

ajkimoto

2:56 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



Superbuis1,

How about this? Just attach it to the load event of the body element":

<head>
<script type="text/javascript">
<!--
//accepts 2 parameters: the form number and element number (rememeber that these are zero based arrays)
function setFocus(formNum, elementNum) {
if (document.forms.length > 0) {
document.forms[formNum].elements[elementNum].focus()
}
}
//-->
</script>
</head>

<body onload="setFocus(0,2)">
<form method="post">
<input type="text" />

<input type="text" />

<input type="submit" value="submit" />
</form>
</body>

ajkimoto