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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Megha Vishwanath

    #1

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

    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.s ubmit() 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.CustSe archFormBean.su bmit();
    }

    }

    function checkKeyPressed ()
    {

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

    validate();
    }
    }

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


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

    Any solutions?


    Thanks and Regards,
    Megha
  • Wired Earp

    #2
    Re: STRUTS-&lt;html:submit &gt; -Hitting enter key does not submit the form

    Megha Vishwanath wrote:
    [color=blue]
    > 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.s ubmit() 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=chec kKeyPressed();
    > b)for the mouseclick submit through <html:submit onclick=validat e();[/color]

    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="retur n 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.isValidate d(), check it out.
    [color=blue]
    > This may be a whole pointless workaround. Does Struts support
    > something more elegant?[/color]

    Server side validation?


    --
    Wired Earp
    Wunderbyte

    Comment

    • Megha Vishwanath

      #3
      Re: STRUTS-&lt;html:submit &gt; -Hitting enter key does not submit the form

      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.

      Comment

      • Megha Vishwanath

        #4
        Re: STRUTS-&lt;html:submit &gt; -Hitting enter key does not submit the form



        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!

        Comment

        Working...