HighDots Forums  

Trouble with onkeypress and enter

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Trouble with onkeypress and enter in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Juan
 
Posts: n/a

Default Trouble with onkeypress and enter - 12-05-2005 , 09:04 AM






Hello:

I'm having a problem with a simple javascript code that checks if the
enter key had been pressed or not. The code works propertly in mozilla,
but in iexplorer it only works one time, the second one the event isn't
throw any more, and I can't catch it.

Anyone can help me?

this is the sample code


function searchIntro(oEvent)
{
if (oEvento.keyCode)
iAscii = oEvent.keyCode;
else if (oEvent.which)
iAscii = oEvent.which;
else
return false;
if (iAscii == 13)
{
sendData();
}
}

<input type="text" id ="textBoxName1" name="CCO" size="69"
onkeypress="SearchIntro(event)"></tr>

Thanks a lot


Reply With Quote
  #2  
Old   
Wayne Dobson
 
Posts: n/a

Default Re: Trouble with onkeypress and enter - 12-06-2005 , 10:21 AM






"Juan" <anacreonteFS (AT) gmail (DOT) com> wrote

Quote:
Hello:

I'm having a problem with a simple javascript code that checks if the
enter key had been pressed or not. The code works propertly in mozilla,
but in iexplorer it only works one time, the second one the event isn't
throw any more, and I can't catch it.

Anyone can help me?

this is the sample code


function searchIntro(oEvent)
{
if (oEvento.keyCode)
iAscii = oEvent.keyCode;
else if (oEvent.which)
iAscii = oEvent.which;
else
return false;
if (iAscii == 13)
{
sendData();
}
}

input type="text" id ="textBoxName1" name="CCO" size="69"
onkeypress="SearchIntro(event)"></tr
Hello.

"SearchIntro" is different from "searchIntro."
"oEvento" is not the same as "oEvent."

Decide on the name of the function and the variable and use the same names
consistently. Also, the event object does not need to be passed to the
function, as it is a global variable.

Try this:

function searchIntro()
{
iAscii = event.keyCode ? event.keyCode : event.which

if(iAscii == null)
return false

if (iAscii == 13)
sendData()
}

--
Wayne
"Aka Dobbie the House Elf."




Reply With Quote
  #3  
Old   
Jasen Betts
 
Posts: n/a

Default Re: Trouble with onkeypress and enter - 12-06-2005 , 10:53 PM



On 2005-12-06, Wayne Dobson <nospam (AT) noaddress (DOT) com> wrote:

Quote:
Decide on the name of the function and the variable and use the same names
consistently.
good advice.

Quote:
Also, the event object does not need to be passed to the
function, as it is a global variable.
it isn't here.

Quote:
Try this:

doesn't work.

Bye.
Jasen


Reply With Quote
  #4  
Old   
Juan
 
Posts: n/a

Default Re: Trouble with onkeypress and enter - 12-07-2005 , 04:04 AM



Thanks Wayne

The code is well writted, the copy/paste to this window and a small
translate has done the rest. The code is case sensitive and the names
are correctly referenced. But still the trouble is there : it only
works for the first time, in internet explorer. If I don't change the
focus to other control, the events don't occurs at this textbox anymore
(only the first name). And it only occurs after deleting letters with
the backspace key.

Any ideas?


Reply With Quote
  #5  
Old   
Wayne Dobson
 
Posts: n/a

Default Re: Trouble with onkeypress and enter - 12-07-2005 , 04:26 AM



"Jasen Betts" <jasen (AT) free (DOT) net.nospam.nz> wrote

Quote:
On 2005-12-06, Wayne Dobson <nospam (AT) noaddress (DOT) com> wrote:

Decide on the name of the function and the variable and use the same
names
consistently.

good advice.

Also, the event object does not need to be passed to the
function, as it is a global variable.

it isn't here.


Try this:


doesn't work.
You're right. My bad. I should have checked, but felt lazy. Pass the the
event object and it will work. It works in NN8.

--
Wayne
"Aka Dobbie the House Elf."




Reply With Quote
  #6  
Old   
Wayne Dobson
 
Posts: n/a

Default Re: Trouble with onkeypress and enter - 12-07-2005 , 09:04 AM



"Juan" <anacreonteFS (AT) gmail (DOT) com> wrote

Quote:
Thanks Wayne

The code is well writted, the copy/paste to this window and a small
translate has done the rest. The code is case sensitive and the names
are correctly referenced. But still the trouble is there : it only
works for the first time, in internet explorer. If I don't change the
focus to other control, the events don't occurs at this textbox anymore
(only the first name). And it only occurs after deleting letters with
the backspace key.

Any ideas?
It works as long as the input box has focus. This is how it is supposed to
work. If you want the event to trigger as long as the window has focus, you
could instead try altering the "BODY" tag, thus:

<BODY onkeypress="searchIntro(event)">

--
Wayne
"Aka Dobbie the House Elf."




Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.