STRUTS-<html:submit> -Hitting enter key does not submit the form

M

Megha Vishwanath

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
 
W

Wired Earp

Megha said:
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
...

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

Better rely on default form behavior where "enter" does actually submit the
form. Just like that. Try the "onsubmit" on the <form> tag like this:

<form action="?" method="?" onsubmit="return isValidated();">

And make sure that your <html:submit/> renders as <input type="submit"/> in
the real world. One might need to call function isValidated() with an
argument - as in sValidated(this) - or as a method of the form - like
this.isValidated(), check it out.
This may be a whole pointless workaround. Does Struts support
something more elegant?

Server side validation?
 
M

Megha Vishwanath

I'm sorry , if you attempted to answer my query. I had a problem
completely unrelated to the <html:submit> or the java script function
shown.

I had a numeric lock on one of my fields that was not recognising the
"Enter" event.

Sorry again,

Megha.
 
M

Megha Vishwanath

I'm sorry , since you attempted to answer my query. I had a problem
completely unrelated to the <html:submit> or the java script function
shown.

I had a numeric lock on one of my fields that was not recognising the
"Enter" event.

Sorry again,

Megha.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top