Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Re: How to update code so ENTER key selects OK button

Reply
Thread Tools

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

 
 
Adrienne Boswell
Guest
Posts: n/a
 
      06-07-2010
Gazing into my crystal ball I observed "ScaryFruit" <(E-Mail Removed)>
writing in news:(E-Mail Removed) o.uk:

> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
File Upload - Change key code for ENTER key on Browse Button bsm Javascript 3 05-29-2007 06:10 AM
File Upload - Change key code for ENTER key on Browse Button bsm ASP .Net 0 05-10-2007 11:13 AM
Enter Key H*ll, control enter key submit button BrianDH ASP .Net Web Controls 3 01-12-2005 08:29 PM
trigger HTML button by enter ENTER key Matt Javascript 1 03-06-2004 07:01 PM



Advertisments