Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Form Submit on Hitting Enter key

 
Abhinay Verma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have the following code


On pressing enter, the form doesn't submit. But if I remove one of input boxes, the form gets submitting.

Please suggest a solution to stop the form from getting submitted on pressing Enter key even when I have just one input box.

Thanks,
Abhinay
 
Balan Raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a hidden field !

 
Eric Pascarello
author
Rancher
Posts: 15385
6
 
Abhinay Verma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to both of you for the quick response

Eric,
I had solved the problem using the keyCode. Was just wondering if there is some other way of fixing it. I guess window.event.keyCode is the only way of making it work

Balan,
The hidden field will not solve the problem.

Thanks & Regards,
Abhinay
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might be able to put

<form onsubmit="return true" ...........>

not sure if that would work.

Eric
 
Abhinay Verma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right Eric

The problem can be solved by using the onsubmit attribute of the form tag.

Thanks,
Abhinay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic