How to update code so ENTER key selects OK button

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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

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


Sub RunScript
    OKClicked.Value = "OK"
End Sub

Sub CancelScript
    OKClicked.Value = "Cancelled"
End Sub



<font size="2" face="Arial">
Username:&nbsp;&nbsp;&nbsp; </font><font face="Arial">
<input type="username" id="UserName" size="40"></font></p>

<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">
<input id=runbutton class="button" type="button" value="Cancel"
name="cancel_button" onClick="CancelScript">


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

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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
Please respond to the group so others can share

Site Timeline