Connecting Tech Pros Worldwide Forums | Help | Site Map

onkeypress, enter and iexplorer

Juan
Guest
 
Posts: n/a
#1: Dec 5 '05
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


Evertjan.
Guest
 
Posts: n/a
#2: Dec 5 '05

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)

Juan
Guest
 
Posts: n/a
#3: Dec 7 '05

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]

Evertjan.
Guest
 
Posts: n/a
#4: Dec 7 '05

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)

Closed Thread