onkeypress, enter and iexplorer 
December 5th, 2005, 02:15 PM
| | | onkeypress, enter and iexplorer
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 | 
December 5th, 2005, 05:05 PM
| | | Re: onkeypress, enter and iexplorer
Juan wrote on 05 dec 2005 in comp.lang.javascript:
[color=blue]
> Anyone can help me?
>
> this is the sample code
>
> function searchIntro(oEvent)[/color]
should be: SearchIntro(oEvent)
case sensitive!!
[color=blue]
> {
> if (oEvento.keyCode)[/color]
should be: oEvent.keyCode
[color=blue]
> iAscii = oEvent.keyCode;
> else if (oEvent.which)
> iAscii = oEvent.which;
> else
> return false;[/color]
a return value is not used by onkeypress
[color=blue]
> if (iAscii == 13)
> {
> sendData();
> }
>}
>
> <input type="text" id ="textBoxName1" name="CCO" size="69"
> onkeypress="SearchIntro(event)"></tr>[/color]
A shorter version of your function is:
function SearchIntro(oEvent){
if ((oEvent.keyCode && oEvent.keyCode==13)
|| (oEvent.which && oEvent.which==13)) {
sendData();
}
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress) | 
December 7th, 2005, 06:45 AM
| | | Re: onkeypress, enter and iexplorer
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:
[color=blue]
> Juan wrote on 05 dec 2005 in comp.lang.javascript:
>[color=green]
> > Anyone can help me?
> >
> > this is the sample code
> >
> > function searchIntro(oEvent)[/color]
>
> should be: SearchIntro(oEvent)
> case sensitive!!
>[color=green]
> > {
> > if (oEvento.keyCode)[/color]
>
> should be: oEvent.keyCode
>[color=green]
> > iAscii = oEvent.keyCode;
> > else if (oEvent.which)
> > iAscii = oEvent.which;
> > else
> > return false;[/color]
>
> a return value is not used by onkeypress
>[color=green]
> > if (iAscii == 13)
> > {
> > sendData();
> > }
> >}
> >
> > <input type="text" id ="textBoxName1" name="CCO" size="69"
> > onkeypress="SearchIntro(event)"></tr>[/color]
>
> A shorter version of your function is:
>
> function SearchIntro(oEvent){
> if ((oEvent.keyCode && oEvent.keyCode==13)
> || (oEvent.which && oEvent.which==13)) {
> sendData();
> }
>
> --
> Evertjan.
> The Netherlands.
> (Replace all crosses with dots in my emailaddress)[/color] | 
December 7th, 2005, 03:45 PM
| | | Re: onkeypress, enter and iexplorer
Juan wrote on 07 dec 2005 in comp.lang.javascript:[color=blue]
> Evertjan. ha escrito:[/color]
[color=blue][color=green]
>> function SearchIntro(oEvent){
>> if ((oEvent.keyCode && oEvent.keyCode==13)
>> || (oEvent.which && oEvent.which==13))
>> sendData();
>> }[/color][/color]
[please do not toppost on usenet]
[color=blue]
>
> 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?[/color]
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)'>
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress) | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | 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.
|