Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript & Carriage Return on Input

Posted on 2000-03-13
9
Medium Priority
?
950 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
ID: 2613933
You might try onKeyDown instead of onKeyPress
0
 
LVL 4

Accepted Solution

by:
brigmar earned 300 total points
ID: 2613983
. and return false (just in case)
0
 

Author Comment

by:wesr
ID: 2613990
'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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 33

Expert Comment

by:knightEknight
ID: 2614001
Which browser are you using?  Also, try brigmar's suggestion.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2614003
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
ID: 2614035
The 'return false' does the trick. Thanks!
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2614045
points to brian (brigmar)  :)
0
 
LVL 4

Expert Comment

by:brigmar
ID: 2614438
woah.. that was just a side comment.
*grin*

Brian
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2615050
None the less.

Michel
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

916 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