This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
    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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Submitting a form on pressing Enter key

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi all,
i have a text field called startdate.
<input type="text" name ="startDt"/>
i need to submit a form when user press enter Key.
how can this be done in jsp.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Report post to moderator
The default behaviour is that the enter key will invoke the firstnext submit button of the form in perspective of the input element. If it isn't there, or if it is the 'wrong' button in the order, then you need to add the submit button or rearrange the ordering of the submit buttons. If that isn't an option somehow, then you'll have to write some Javascript which does a form.submit() or invokes the desired submit button and attach it to the onkeypress event. The event.keyCode of the enter key is 13.
[ August 25, 2008: Message edited by: Bauke Scholtz ]
 
payal Jain
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Report post to moderator
i dont have submit button on the page..
Its just onEnter on the date I have to perform some search.
now how can i do that.
 
Marshal
Posts: 67288
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Easiest solution: add a submit button. Make it invisible, if you want.
[ August 25, 2008: Message edited by: Bear Bibeault ]
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Report post to moderator

Originally posted by payal Jain:
i dont have submit button on the page..
Its just onEnter on the date I have to perform some search.
now how can i do that.


Reread the last two sentences of my answer.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Payal,

here is total answer for your question with code snippet
just add for text field

onKeyUp event submitenterfun(this,event)


function submitenterfun(myfield,e){

var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;
else
return true;

if (keycode == 13){

document.forms.loginForm.submit();
return false;
}
else
return true;
}


Thank You.
Have a Nice Time.

-Santosh
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Report post to moderator
Cleaner example:




[ August 26, 2008: Message edited by: Bauke Scholtz ]
 
payal Jain
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Report post to moderator
thanks for y'r replies..
It works but only when Submit button is present.
If i remove the Submit button the script dosent work.
 
Bear Bibeault
Marshal
Posts: 67288
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
As you have started a new topic on this matter, I am closing this discussion.
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!