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>