SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ACCESSKEY attribute not working properly

    Hi,
    I've got this login form where there's a username and password field ..and a login button (duh!)... i've used ACCESSKEY attribute for the login button.. and set it to 'enter' key.. but when i hit enter..the Javascript function associated with the button is not getting called.. can someone help me? here
    s my code.. thanks..
    <form>
    <input type=hidden name=module value=login>
    <table>
    <tr style="">
    <td><span class="headtext">username </span></td>
    <td><input type=text name="username" id="username" value="" /></td></tr>
    <tr style="">
    <td><span class="headtext">password </span></td>
    <td><input type="password" name="password" id="password" value=""/></td></tr>
    </table><br/>
    <input type="button" onclick="liveLogin('login')" value="login" style="margin-left:1em" ACCESSKEY='enter'></input>
    </form><br>

    does ACCESSKEY function work only when input type=submit?

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't set the accesskey to Enter. Only single-letter accesskeys are allowed.

    The actual invocation depends on the user agent. For instance, IE/Win and Firefox/Win use Alt+accesskey, Mac browsers often use Ctrl+accesskey, and Opera uses Shift+Esc&#160;accesskey.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh... can you then tell me how the code should be modified to invoke the javascript function when i hit enter?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Enter will submit the form when you are on appropriate form fields.

    As such, you can tell the form to run a function when it's submitted, which goes through if it returns true and cancels the submission if it returns cancel.

    Code HTML4Strict:
    <form onsubmit="validate();">
    . . .
    </form>

    Other more complex ways are to capture a keypress, and if it's the enter key (code 13) run a certain function.

    Code HTML4Strict:
    <body onkeypress="capture(13, function() { processEnter(); });">
    . . .
    </form>

    The capture() function will for now, be left for later.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •