Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 954
  • Last Modified:

Javascript & Carriage Return on Input

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
wesr
Asked:
wesr
  • 3
  • 2
  • 2
  • +1
1 Solution
 
knightEknightCommented:
You might try onKeyDown instead of onKeyPress
0
 
brigmarCommented:
. and return false (just in case)
0
 
wesrAuthor Commented:
'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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
knightEknightCommented:
Which browser are you using?  Also, try brigmar's suggestion.
0
 
Michel PlungjanIT ExpertCommented:
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
 
wesrAuthor Commented:
The 'return false' does the trick. Thanks!
0
 
knightEknightCommented:
points to brian (brigmar)  :)
0
 
brigmarCommented:
woah.. that was just a side comment.
*grin*

Brian
0
 
Michel PlungjanIT ExpertCommented:
None the less.

Michel
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now