How can I do a button as defaulte selection

R

Raju

Hi Friends,
I have six buttons in my screen. When ever the user enter into my
screen I would like make login button as the default one in the
screen. How can I do that? Can any of you please suggest me....

Thanks in advance.
 
J

Jukka K. Korpela

12.5.2011 13:41, Raju kirjoitti:
I have six buttons in my screen. When ever the user enter into my
screen I would like make login button as the default one in the
screen. How can I do that? Can any of you please suggest me....

The simplest method is to use the attribute
autofocus
in the button element. This works even when scripting is off, though it
does not yet work on all browsers (e.g., IE - even IE 9 - does not
recognize the autofocus attribute).

You can use the older technique, the focus() method in Javascript,
though it has the drawback of not being overridable by users (as the
autofocus attribute is expected to be). It may also confuse the user if
the page e.g. has a text input box and the user has started typing
there, then the focus() method steals the focus.

You might combine the two techniques:

<body onload="init()">
[...]
<input id="login" type="button" value="Login" onclick="login()" autofocus>
<script>
function init(){
var login = document.getElementById("login");
if(!("autofocus" in login)) {
login.focus(); }}
</script>
 

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

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top