Connecting Tech Pros Worldwide Help | Site Map

onkeypress, enter and iexplorer

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 5th, 2005, 02:15 PM
Juan
Guest
 
Posts: n/a
Default 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


  #2  
Old December 5th, 2005, 05:05 PM
Evertjan.
Guest
 
Posts: n/a
Default 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)

  #3  
Old December 7th, 2005, 06:45 AM
Juan
Guest
 
Posts: n/a
Default 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]

  #4  
Old December 7th, 2005, 03:45 PM
Evertjan.
Guest
 
Posts: n/a
Default 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)

 

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.