Re: How to update code so ENTER key selects OK button

Discussion in 'HTML' started by Adrienne Boswell, Jun 8, 2010.

  1. Gazing into my crystal ball I observed "ScaryFruit" <>
    writing in news::

    > Hi,
    >
    > I found the below code on the web which I've adapted slightly to
    > prompt for a username and password, and also so the cursor
    > automatically starts in the "Username" box.


    Let the user position the cursor. If the user has already started
    typing in the field, and the script puts the user back at the beginning
    of the field, the user may mistype the information. If the fields are
    in an obvious place, the user will have no problem finding it.


    > I'd also like to
    > configure this so when the user pushes ENTER on the keyboard, it
    > selects the OK button. Could someone show me how to do this?


    What happens if I have started typing, and accidentally hit the enter
    key? The wrong information will be submitted, and I will be frustrated.
    Let the user use the submit button.

    >
    > (And, as an aside, if anyone can tell me the IE security settings to
    > change so, when running the script from the local machine, I don't
    > keep getting a warning saying IE has restricted the webpage from
    > running scripts of ActiveX controls, that would also be helpful!)
    >
    > Thanks in advance.
    >
    >
    ><SCRIPT LANGUAGE="VBScript">
    >
    > Sub RunScript
    > OKClicked.Value = "OK"
    > End Sub
    >
    > Sub CancelScript
    > OKClicked.Value = "Cancelled"
    > End Sub
    >
    ></SCRIPT>


    If you hold a gun to the user's head, you may be able to get him or her
    to change their security settings. VB script is always ActiveX, so will
    always give that warning.

    >
    ><BODY>
    >
    ><font size="2" face="Arial">
    > Username:&nbsp;&nbsp;&nbsp; </font><font face="Arial">
    ><input type="username" id="UserName" size="40"></font></p>
    ><script>document.getElementById('UserName').focus()</script>
    >
    ><font size="2" face="Arial">
    > Password:&nbsp;&nbsp;&nbsp; </font><font face="Arial">
    ><input type="password" name="UserPassword" size="40"></font></p>
    >
    ><input type="hidden" name="OKClicked" size = "20">
    >
    ><input id=runbutton class="button" type="button" value=" OK "
    > name="ok_button" onClick="RunScript">
    > &nbsp;&nbsp;&nbsp;
    ><input id=runbutton class="button" type="button" value="Cancel"
    > name="cancel_button" onClick="CancelScript">
    >
    ></BODY>
    >
    >
    >


    Oh, the horror! The font element is deprecated in favor of CSS.
    Character values must be quoted in element attributes.

    Just use a regular submit button, and take out the unnecessary
    scripting. Make sure that you check server side for the values you are
    expecting from the client.

    --
    Adrienne Boswell at Home
    Arbpen Web Site Design Services
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
    Adrienne Boswell, Jun 8, 2010
    #1
    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. bsm
    Replies:
    0
    Views:
    1,306
  2. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    391
    Anders Matthiessen
    Jan 12, 2005
  3. M P
    Replies:
    1
    Views:
    466
  4. Matt
    Replies:
    1
    Views:
    505
    Michael Winter
    Mar 6, 2004
  5. bsm
    Replies:
    3
    Views:
    284
Loading...

Share This Page