How can I do a button as defaulte selection

Discussion in 'HTML' started by Raju, May 12, 2011.

  1. Raju

    Raju Guest

    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.
     
    Raju, May 12, 2011
    #1
    1. Advertising

  2. 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>

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, May 12, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Niederberger
    Replies:
    2
    Views:
    16,554
    Christian Kaufhold
    Jan 7, 2005
  2. Andrew Crowe
    Replies:
    1
    Views:
    4,482
    Andrew Crowe
    Sep 13, 2004
  3. curiousity

    HOWTO autopost the selection list upon selection

    curiousity, Nov 21, 2003, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    275
    curiousity
    Nov 21, 2003
  4. Loebb
    Replies:
    0
    Views:
    205
    Loebb
    Feb 23, 2004
  5. Replies:
    1
    Views:
    216
Loading...

Share This Page