Connecting Tech Pros Worldwide Help | Site Map

Press Enter on a text box

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 02:29 PM
JCO
Guest
 
Posts: n/a
Default Press Enter on a text box

How's come when I press the enter key, I can't get it to execute the correct
password.
It seems that I'm forced to press the button. I want to be able to do both.

How is this done?



  #2  
Old July 20th, 2005, 02:29 PM
kaeli
Guest
 
Posts: n/a
Default Re: Press Enter on a text box

In article <k0RWb.1679$wD5.1640@nwrddc03.gnilink.net>,
J.Oliviero@verizon.net enlightened us with...[color=blue]
> How's come when I press the enter key, I can't get it to execute the correct
> password.
> It seems that I'm forced to press the button. I want to be able to do both.
>[/color]


You're going to have be a lot more specific.
Got a url?

--
--
~kaeli~
A midget fortune teller who escapes from prison is a small
medium at large.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

  #3  
Old July 20th, 2005, 02:29 PM
JCO
Guest
 
Posts: n/a
Default Re: Press Enter on a text box

Sorry for the lack of detail. Site is not hosted at this time.
I will try again. I have a logon form (logon.htm) that contains a Textbox,
Push Button (label = Enter Password) & and a Clear button (label is clear).
Simple as that.

Currently, you would enter the password in the text box and select the
button. The script does the rest. I want to modify it by allowing the user
to type in the password and simply press the enter key as another method to
validate the form. I tried to trap the enter key as shown, but it is not
working.

<FORM NAME="frmPassword" onSubmit="return valForm()">
<input type=password name="txtInput" size="15" onkeypress="onEnter();" >
<input type="button" value="Enter Password" name="btnEnter"
onclick="valForm();">
<input type="reset" value="Clear" name="btnClear"></p>

function onEnter(){
if(event.keyCode==13)
document.frmPassword.btnEnter.click();
}

What is wrong with this?



"kaeli" <tiny_one@NOSPAM.comcast.net> wrote in message
news:MPG.1a95a74a29351766989c1b@nntp.lucent.com...[color=blue]
> In article <k0RWb.1679$wD5.1640@nwrddc03.gnilink.net>,
> J.Oliviero@verizon.net enlightened us with...[color=green]
> > How's come when I press the enter key, I can't get it to execute the[/color][/color]
correct[color=blue][color=green]
> > password.
> > It seems that I'm forced to press the button. I want to be able to do[/color][/color]
both.[color=blue][color=green]
> >[/color]
>
>
> You're going to have be a lot more specific.
> Got a url?
>
> --
> --
> ~kaeli~
> A midget fortune teller who escapes from prison is a small
> medium at large.
> http://www.ipwebdesign.net/wildAtHeart
> http://www.ipwebdesign.net/kaelisSpace
>[/color]


  #4  
Old July 20th, 2005, 02:30 PM
Michael Winter
Guest
 
Posts: n/a
Default Re: Press Enter on a text box

On Fri, 13 Feb 2004 02:29:56 GMT, JCO <J.Oliviero@verizon.net> wrote:
[color=blue]
> <FORM NAME="frmPassword" onSubmit="return valForm()">
> <input type=password name="txtInput" size="15" onkeypress="onEnter();" >
> <input type="button" value="Enter Password" name="btnEnter"
> onclick="valForm();">
> <input type="reset" value="Clear" name="btnClear"></p>
>
> function onEnter(){
> if(event.keyCode==13)
> document.frmPassword.btnEnter.click();
> }
>
> What is wrong with this?[/color]

You don't cancel the event. Try:

function onEnter( evt, frm ) {
var keyCode = null;

if( evt.which ) {
keyCode = evt.which;
} else if( evt.keyCode ) {
keyCode = evt.keyCode;
}
if( 13 == keyCode ) {
frm.btnEnter.click();
return false;
}
return true;
}
...
<input type="password" name="txtInput" size="15"
onkeypress="return onEnter(event,this.form);" >

This should work (partially tested on) Opera 7.23, Netscape 7, IE 6, and
Mozilla 1.6. Your original code could only have worked on IE and Opera;
Netscape and Mozilla don't support a global event object, or event.keyCode.

Mike

--
Michael Winter
M.Winter@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
  #5  
Old July 20th, 2005, 02:30 PM
JCO
Guest
 
Posts: n/a
Default Re: Press Enter on a text box

It is working now. Thanks for your help.

"Michael Winter" <M.Winter@blueyonder.co.invalid> wrote in message
news:opr3a0tmd65vklcq@news-text.blueyonder.co.uk...[color=blue]
> On Fri, 13 Feb 2004 02:29:56 GMT, JCO <J.Oliviero@verizon.net> wrote:
>[color=green]
> > <FORM NAME="frmPassword" onSubmit="return valForm()">
> > <input type=password name="txtInput" size="15" onkeypress="onEnter();" >
> > <input type="button" value="Enter Password" name="btnEnter"
> > onclick="valForm();">
> > <input type="reset" value="Clear" name="btnClear"></p>
> >
> > function onEnter(){
> > if(event.keyCode==13)
> > document.frmPassword.btnEnter.click();
> > }
> >
> > What is wrong with this?[/color]
>
> You don't cancel the event. Try:
>
> function onEnter( evt, frm ) {
> var keyCode = null;
>
> if( evt.which ) {
> keyCode = evt.which;
> } else if( evt.keyCode ) {
> keyCode = evt.keyCode;
> }
> if( 13 == keyCode ) {
> frm.btnEnter.click();
> return false;
> }
> return true;
> }
> ...
> <input type="password" name="txtInput" size="15"
> onkeypress="return onEnter(event,this.form);" >
>
> This should work (partially tested on) Opera 7.23, Netscape 7, IE 6, and
> Mozilla 1.6. Your original code could only have worked on IE and Opera;
> Netscape and Mozilla don't support a global event object, or[/color]
event.keyCode.[color=blue]
>
> Mike
>
> --
> Michael Winter
> M.Winter@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)[/color]


  #6  
Old July 20th, 2005, 02:30 PM
Ivo
Guest
 
Posts: n/a
Default Re: Press Enter on a text box

" JCO" <J.Oliviero@verizon.net> wrote in message
news:EEWWb.14139$1S1.2042@nwrddc01.gnilink.net...
[color=blue]
> <FORM NAME="frmPassword" onSubmit="return valForm()">
> <input type=password name="txtInput" size="15" onkeypress="onEnter();" >
> <input type="button" value="Enter Password" name="btnEnter"
> onclick="valForm();">
> <input type="reset" value="Clear" name="btnClear"></p>
>
> function onEnter(){
> if(event.keyCode==13)
> document.frmPassword.btnEnter.click();
> }
>[/color]

I believe I noticed that the "Enter key" functionality depends on the
presence of an <input type="submit"> in the form. I had a form where I
replaced it with a <button> (to allow underlined letters) and the Enter key
stopped working there and then. The non-javascript dependent solution I
ended up with was to add an <input type="submit"> with a height and width of
1.
HTH
Ivo


  #7  
Old July 20th, 2005, 02:31 PM
JCO
Guest
 
Posts: n/a
Default Re: Press Enter on a text box

Are you saying to change the button (that says "Enter Password") should be
of type submit or are you saying the textbox should be of type submit.

I have changed the textbox to type=password; this makes sense.

"Ivo" <no@thank.you> wrote in message
news:402d0888$0$70750$4a441750@news.euronet.nl...[color=blue]
> " JCO" <J.Oliviero@verizon.net> wrote in message
> news:EEWWb.14139$1S1.2042@nwrddc01.gnilink.net...
>[color=green]
> > <FORM NAME="frmPassword" onSubmit="return valForm()">
> > <input type=password name="txtInput" size="15" onkeypress="onEnter();" >
> > <input type="button" value="Enter Password" name="btnEnter"
> > onclick="valForm();">
> > <input type="reset" value="Clear" name="btnClear"></p>
> >
> > function onEnter(){
> > if(event.keyCode==13)
> > document.frmPassword.btnEnter.click();
> > }
> >[/color]
>
> I believe I noticed that the "Enter key" functionality depends on the
> presence of an <input type="submit"> in the form. I had a form where I
> replaced it with a <button> (to allow underlined letters) and the Enter[/color]
key[color=blue]
> stopped working there and then. The non-javascript dependent solution I
> ended up with was to add an <input type="submit"> with a height and width[/color]
of[color=blue]
> 1.
> HTH
> Ivo
>
>[/color]


  #8  
Old July 20th, 2005, 02:31 PM
Michael Winter
Guest
 
Posts: n/a
Default Re: Press Enter on a text box

On Fri, 13 Feb 2004 20:47:37 GMT, JCO <J.Oliviero@verizon.net> wrote:

[Fixed top-post]
[color=blue]
> "Ivo" <no@thank.you> wrote in message
> news:402d0888$0$70750$4a441750@news.euronet.nl...
>[color=green]
>> I believe I noticed that the "Enter key" functionality depends on the
>> presence of an <input type="submit"> in the form.[/color][/color]

[snip]
[color=blue]
> Are you saying to change the button (that says "Enter Password") should
> be of type submit or are you saying the textbox should be of type submit.[/color]

What I believe Ivo is trying to say is that when a submit button is
present in a form and the Enter key is pressed whilst a textbox or
password field[1] in the same form has focus, the form should be submitted.

If you change btnEnter to type submit, you might not need the script I
presented (I wasn't really thinking about that, I just fixed your script).

Mike

[1] I don't remember if this extends to other form controls.

--
Michael Winter
M.Winter@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.