Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

onkeyup function

 
Ranch Hand
Posts: 2028
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am calling a JS function from the onkeyup event of an input text box. When I hit the enter key in that box the form submits. How can I keep this from happening?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the keycode, figure out the code for enter, use an if statemenet and learn about event bubbling http://www.quirksmode.org/js/events_order.html or use return false.

Eric
 
Steve Dyke
Ranch Hand
Posts: 2028
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my JS function, again it works if the input text box is outside of my form tags but not if it is within the tags.

The keyCode = 13 and I have return false in my function.


[ December 02, 2008: Message edited by: Steve Dyke ]
 
Steve Dyke
Ranch Hand
Posts: 2028
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could sure use some more help with this issue.
[ December 02, 2008: Message edited by: Steve Dyke ]
 
Marshal
Posts: 67430
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this.
 
Bear Bibeault
Marshal
Posts: 67430
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "doesn't work" mean in this case?
 
Steve Dyke
Ranch Hand
Posts: 2028
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about not waiting. I finally figured out my problem. The input text box I was using did not have another control to lose focus too. I added another input text box, hid it, and it works fine.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still trying to figure out how your function works at all.

what you want is not:



but:


[ December 05, 2008: Message edited by: steve calflin ]
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also the code is not cross browser friendly.

should have a event in the arguments of the function, should be using window.event also.

Eric
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic