File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic

Submitting a form on pressing Enter key

 
payal Jain
Ranch Hand
Posts: 50
  • 0
  • 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.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • 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
  • 0
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64200
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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
  • 0
  • 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.
 
Santoshkumar Jeevan Pawar
Greenhorn
Posts: 27
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64200
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic