Solved

Javascript & Carriage Return on Input

Posted on 2000-03-13
9
905 Views
Last Modified: 2008-03-03
I am trying to get a <cr> entered in a text input field to cause a form submit, I.E.,

<form action="....">
  <input type="text" name="abc" onkeypress="if(window.event.keycode == 13) document.forms[0].submit()">
</form>

This sort of works, but it beeps a lot in the process. Why is it beeping and/or is there a better way to do this?

0
Comment
Question by:wesr
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
You might try onKeyDown instead of onKeyPress
0
 
LVL 4

Accepted Solution

by:
brigmar earned 100 total points
Comment Utility
. and return false (just in case)
0
 

Author Comment

by:wesr
Comment Utility
'keydown' seems to exhibit the same behavior as 'keypress'. I believe the problem has to do with some default handling of the <cr> return by the browser as a <cr> entered into a text field that has no JavaScript associated with it causes beeping. The submit() does actually take place after all the beeps.
0
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
Which browser are you using?  Also, try brigmar's suggestion.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Netscape: return false to cancel beep as brian said
IE: beeps if no means of submission - e.g. single entry field or submit button

Michel
0
 

Author Comment

by:wesr
Comment Utility
The 'return false' does the trick. Thanks!
0
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
points to brian (brigmar)  :)
0
 
LVL 4

Expert Comment

by:brigmar
Comment Utility
woah.. that was just a side comment.
*grin*

Brian
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
None the less.

Michel
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now