handling onblur

Discussion in 'Javascript' started by hrpreet, Feb 16, 2006.

  1. hrpreet

    hrpreet Guest

    Hi All,

    I have few textfields and dropdowns in my jsp, form is submitted on
    clicking an image link.
    In case there is an error for instance some text field is left empty,
    then message is displayed below respective fields ( using spans, inner
    html). The message is displayed onblur event of the field. So if there
    was an error then message is displayed, now if the user corrects the
    error and clicks the link then first the message disaapears ,which is
    desired ,but he has to click again to submit the form. please suggest a
    way to handle this. So that user doesn't have to click the link twice
    to submit the form.I tried having onmousedown and onfocus events on
    image , but then sometimes the form was submitted twice which gave
    backend errors.

    Thanks
     
    hrpreet, Feb 16, 2006
    #1
    1. Advertising

  2. hrpreet

    web.dev Guest

    hrpreet wrote:
    > Hi All,
    >
    > I have few textfields and dropdowns in my jsp, form is submitted on
    > clicking an image link.
    > In case there is an error for instance some text field is left empty,
    > then message is displayed below respective fields ( using spans, inner
    > html). The message is displayed onblur event of the field. So if there
    > was an error then message is displayed, now if the user corrects the
    > error and clicks the link then first the message disaapears ,which is
    > desired ,but he has to click again to submit the form. please suggest a
    > way to handle this. So that user doesn't have to click the link twice
    > to submit the form.I tried having onmousedown and onfocus events on
    > image , but then sometimes the form was submitted twice which gave
    > backend errors.
    >
    > Thanks


    A form element has an onsubmit event handler. Consider using that to
    validate your form instead of using onblur. For example:

    html:

    <form action = "action.jsp" method = "post" onsubmit = "return
    validate(this)">
    ....[elements]...
    </form>

    javascript:

    function validate(myForm)
    {
    //perform your validation routine here
    if(...)
    {
    //display your error message
    //return false will cause the form NOT to submit
    return false;
    }

    //return true will cause the form to submit
    return true;
    }

    It would be also nice to take into consideration if the user has
    disabled javascript. Therefore you should also do validation on the
    server side.
     
    web.dev, Feb 16, 2006
    #2
    1. Advertising

  3. hrpreet

    hrpreet Guest

    Thanks a lot for your reply.
    But it was client's requirement to hav it onblur. i kept trying
    different options, and capturing onmouse down event on image has helped
    me.

    You are right about server side validations.

    Thanks again
     
    hrpreet, Feb 17, 2006
    #3
    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. simo sentissi
    Replies:
    0
    Views:
    3,905
    simo sentissi
    Aug 25, 2003
  2. Jeffrey
    Replies:
    2
    Views:
    6,720
    Jeffrey
    Oct 16, 2003
  3. =?Utf-8?B?Sm9lLkRhdHRpbG8=?=

    Client Side OnBlur Triggering Validation

    =?Utf-8?B?Sm9lLkRhdHRpbG8=?=, Jun 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,714
    Peter Blum
    Jun 18, 2004
  4. neil S via DotNetMonster.com

    custom control onblur postback

    neil S via DotNetMonster.com, Apr 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    811
    =?Utf-8?B?UGF1bA==?=
    Apr 28, 2005
  5. Emmes
    Replies:
    1
    Views:
    155
Loading...

Share This Page