SetFocus issue...

N

NiallM

Any chance anyone could spare a sec to see where i'm going wrong here?

On loading a page i'm trying to sefocus to a button on the page, (the only
button) so that I can press return and it will have the effect of clicking
it.

Here is what I'm doing at the moment but it's still not passing focus...

<HTML>
<HEAD>

<script type="button/javascript">

function setFocus()
{
document.button.focus();
}
</script>

</HEAD>
<TITLE>Successful logout</TITLE>

<BODY class="PageBody" onload=setFocus() >
<BR><BR><BR><BR><BR><BR><BR>
<TABLE class="WidgetPanel">
<TR>
<TD class="WidgetCell" align="center">
<SPAN class="DataLabel">
You have been logged out successfully.
<BR><BR><BR><BR><BR>
</SPAN>
</TD>
</TR>
<TR>
<TD align="center">
<INPUT class="button" type="button" onclick="location.replace(
'./index.jsp' )" value="Login" />
</TD>
</TR>
</TABLE>
</BODY>
</HTML>


Cheers if anyone has any idea's

N.
 
S

Steve Pugh

NiallM said:
Any chance anyone could spare a sec to see where i'm going wrong here?

On loading a page i'm trying to sefocus to a button on the page, (the only
button) so that I can press return and it will have the effect of clicking
it.

As you talk about yourself being the one who will press return I
presume this is a personal page that no one else will use. If it is
going on the WWW for general use then don't muck about with the focus
at all.
Here is what I'm doing at the moment but it's still not passing focus...

<HTML>
<HEAD>

<script type="button/javascript">

type="button/javascript ? Where does that come from?
function setFocus()
{
document.button.focus();

That assumes the MSIE document model and gives focus to the element
with id="button". The standard way of doing this would be
document.getElementById('button').focus() .
}
</script>

</HEAD>
<TITLE>Successful logout</TITLE>

The title element should be a child of the head element.

<BODY class="PageBody" onload=setFocus() >

setFocus() should be quoted as ( and ) are not on the list of
characters that can be used in unquoted attribute values.
<BR><BR><BR><BR><BR><BR><BR>

Hello? It's 2005, use CSS margins.

<INPUT class="button" type="button" onclick="location.replace(
'./index.jsp' )" value="Login" />

If all the button is doing is calling a new page then an ordinary link
is more reliable. You can even style it to look like a button if you
want.

As your button doesn't have id="button" it isn't affected at all by the
JavaScript function provided.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top