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

Discussion in 'Javascript' started by Megha Vishwanath, Jul 18, 2004.

  1. 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
    Megha Vishwanath, Jul 18, 2004
    #1
    1. Advertising

  2. Megha Vishwanath

    Wired Earp Guest

    Megha Vishwanath wrote:

    > 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?


    --
    Wired Earp
    Wunderbyte
    Wired Earp, Jul 19, 2004
    #2
    1. Advertising

  3. 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.
    Megha Vishwanath, Jul 20, 2004
    #3
  4. 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.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Megha Vishwanath, Jul 20, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Megha Vishwanath
    Replies:
    2
    Views:
    9,797
    tutorialsmaster
    Oct 2, 2009
  2. Sunfire
    Replies:
    2
    Views:
    1,046
    Sunfire
    Nov 6, 2007
  3. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    367
    Anders Matthiessen
    Jan 12, 2005
  4. Abraham Luna

    hitting enter does not submit form but refreshes page?

    Abraham Luna, Sep 2, 2005, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    319
    Abraham Andres Luna
    Oct 27, 2005
  5. Guest
    Replies:
    2
    Views:
    1,561
    Guest
    Oct 25, 2004
Loading...

Share This Page