onkeypress, enter and iexplorer

J

Juan

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
 
E

Evertjan.

Juan wrote on 05 dec 2005 in comp.lang.javascript:
Anyone can help me?

this is the sample code

function searchIntro(oEvent)

should be: SearchIntro(oEvent)
case sensitive!!
{
if (oEvento.keyCode)

should be: oEvent.keyCode
iAscii = oEvent.keyCode;
else if (oEvent.which)
iAscii = oEvent.which;
else
return false;

a return value is not used by onkeypress
if (iAscii == 13)
{
sendData();
}
}

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

A shorter version of your function is:

function SearchIntro(oEvent){
if ((oEvent.keyCode && oEvent.keyCode==13)
|| (oEvent.which && oEvent.which==13)) {
sendData();
}
 
J

Juan

Thanks evertjan, but the trouble's still here : I made a mistakes
copying function to this message :), but the case sensitive is
correctly implemented.

It only works the first time, the second one, on Internet Explorer,
fails and doesn't capture any other onkeypress event.Mozilla runs fine
the code everytime I use it.

whats happening?

Juan

Evertjan. ha escrito:
 
E

Evertjan.

Juan wrote on 07 dec 2005 in comp.lang.javascript:
Evertjan. ha escrito:

[please do not toppost on usenet]

Thanks evertjan, but the trouble's still here : I made a mistakes
copying function to this message :), but the case sensitive is
correctly implemented.

It only works the first time, the second one, on Internet Explorer,
fails and doesn't capture any other onkeypress event.Mozilla runs fine
the code everytime I use it.

whats happening?

That depends on your function sendData().
Always try an adviced code on itself first.
This works every time in IE:

<script type='text/javascript'>

function SearchIntro(oEvent){
if ((oEvent.keyCode && oEvent.keyCode==13)
|| (oEvent.which && oEvent.which==13)) {
alert('<return> detected');
}
}
</script>

<input onkeypress='SearchIntro(event)'>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top