Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > STRUTS- <html:submit> does not submit on pressing Enter key

Reply
Thread Tools

STRUTS- <html:submit> does not submit on pressing Enter key

 
 
Megha Vishwanath
Guest
Posts: n/a
 
      07-18-2004
Hi,

I have a struts form <html:form> in which although the focus rests on
the submit button, hitting the enter key does not submit the form.

I tried capturing the Enter key event and followed it by the
document.form.submit() but this takes me through the validation
attached with the submit twice( giving me all the alerts twice).

Here's the code
function validate()
{

var validateVal = isValidated();//this guy does all the validation
if(!validateVal)
{
return false;
}
else
{
document.CustSearchFormBean.submit();
}

}

function checkKeyPressed()
{

if(window.event.keyCode=="13")
{

validate();
}
}

I call validate
a)for the enter button through <BODY onkeypress=checkKeyPressed();
b)for the mouseclick submit through <html:submit onclick=validate();


This may be a whole pointless workaround. Does Struts support
something more elegant?

Any solutions?

Thanks and Regards,
Megha.
 
Reply With Quote
 
 
 
 
Murray
Guest
Posts: n/a
 
      07-18-2004

"Megha Vishwanath" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> I have a struts form <html:form> in which although the focus rests on
> the submit button, hitting the enter key does not submit the form.
>
> I tried capturing the Enter key event and followed it by the
> document.form.submit() but this takes me through the validation
> attached with the submit twice( giving me all the alerts twice).
>
> Here's the code
> function validate()
> {
>
> var validateVal = isValidated();//this guy does all the validation
> if(!validateVal)
> {
> return false;
> }
> else
> {
> document.CustSearchFormBean.submit();
> }
>
> }
>
> function checkKeyPressed()
> {
>
> if(window.event.keyCode=="13")
> {
>
> validate();
> }
> }
>
> I call validate
> a)for the enter button through <BODY onkeypress=checkKeyPressed();
> b)for the mouseclick submit through <html:submit onclick=validate();


No you don't need any of that ugliness. First, your validate() method needs
to return true or false. At the moment it's only returning false, or calling
form.submit (which is not necessary since the submit button does that for
you). Then the onclick should be onclick="return validate();" <-- note the
return.

However, the normal (and best?) way to do this is to use the form's onsubmit
event instead. Doing it this way also allows you to pass the form object to
the validate method e.g. onsubmit="return validate(this);" You can access
the form directly instead of using document.formName <-- you'd have to
change your validation code if you decided to rename your form bean in the
future.


 
Reply With Quote
 
 
 
 
tutorialsmaster tutorialsmaster is offline
Junior Member
Join Date: Oct 2009
Posts: 1
 
      10-02-2009
Recently I came across posting which helped me to fix a similar problem.
Check it and see if this helps you...
forum.tutorials2learn.com/viewtopic.php?f=5&t=2
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Submit a form by pressing the enter key Chinnala ASP .Net 3 01-10-2007 10:37 AM
Does anyone know why Safari browser does not submit on enter key. zazzaron@cox.net HTML 1 12-20-2005 07:50 PM
Enter Key H*ll, control enter key submit button BrianDH ASP .Net Web Controls 3 01-12-2005 08:29 PM
STRUTS-<html:submit> -Hitting enter key does not submit the form Megha Vishwanath Javascript 3 07-20-2004 05:45 AM
Pressing ENTER does not invoke the only SUBMIT button. Neo ASP .Net 2 05-11-2004 05:04 PM



Advertisments