how to stop executing if validation returns false

Discussion in 'Javascript' started by mak, Mar 8, 2008.

  1. mak

    mak Guest

    hi,
    i'm doing a validation in a JSP page. in two fields
    function valli()
    {
    valid = true;

    if ( document.all['lecture_held'].value == "")
    {
    alert("Please Select total Lecture Cunducted");
    document.all['lecture_held'].focus();
    valid = false;
    }
    if ( document.all['att'].value == "")
    {
    alert("Please Enter Students Attendance");
    document.all['att'].focus();
    valid = false;
    }
    return valid;
    }

    when it returns false then it executes the jsp code...

    what should i do so that when it return true then only it should
    execute the jsp code....

    please help

    thank you
     
    mak, Mar 8, 2008
    #1
    1. Advertising

  2. mak

    VK Guest

    On Mar 8, 10:55 pm, mak <> wrote:

    > what should i do so that when it return true then only it should
    > execute the jsp code....


    <form onsubmit="return valli(this)">

    with valli returning false or true respectively.

    P.S.
    > if ( document.all['lecture_held'].value == "")


    Despite document.all collection became an alternative standard to
    document.getElementById, some browsers support it only in so called
    "quirk mode" caused by a particular DOCTYPE declaration or by the
    absence of such. You don't want to break your script by simply
    switching to the strict mode, so you may want to use standard tools
    instead.

    <form onsubmit="return valli(this)" ...

    function valli(frm) {
    if (frm.lecture_held.value == "") {
    frm.lecture_held.focus();
    return false;
    }
    else if {
    // ...
    }
    else if {
    // ...
    }
    else {
    return true;
    }
    }
     
    VK, Mar 8, 2008
    #2
    1. Advertising

  3. mak

    mak Guest


    >
    > <form onsubmit="return valli(this)" ...
    >
    > function valli(frm) {
    >  if (frm.lecture_held.value == "") {
    >   frm.lecture_held.focus();
    >   return false;
    >  }
    >  else if {
    >   // ...
    >  }
    >  else if {
    >   // ...
    >  }
    >  else {
    >   return true;
    >  }
    >
    >
    >
    > }



    even using like this its submiting the value, Even though I'm not
    giving any value to the text box.
     
    mak, Mar 8, 2008
    #3
  4. mak wrote:
    > [VK wrote:]
    >> <form onsubmit="return valli(this)" ...
    >>
    >> function valli(frm) {
    >> if (frm.lecture_held.value == "") {
    >> frm.lecture_held.focus();
    >> return false;
    >> }
    >> else if {
    >> // ...
    >> }
    >> else if {
    >> // ...
    >> }
    >> else {
    >> return true;
    >> }
    >> }

    >
    > even using like this its submiting the value, Even though I'm not
    > giving any value to the text box.


    That is highly unlikely, you must have done something different to this.
    Make sure that you always return a value from valli(), that you actually
    have a `return' statement in the `onsubmit' attribute, and that you are
    submitting using a submit button (`<input type="submit" ...>' or `<input
    type="image" ...>'), not a click button (`<input type="button" onclick="..."
    ....>').


    Please don't trim the attribution line next time.


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
     
    Thomas 'PointedEars' Lahn, Mar 8, 2008
    #4
  5. mak

    Evertjan. Guest

    mak wrote on 08 mrt 2008 in comp.lang.javascript:

    > hi,
    > i'm doing a validation in a JSP page. in two fields


    A Java Server Page?

    Java has nothing to do with Javascript.


    > function valli()
    > {
    > valid = true;
    >
    > if ( document.all['lecture_held'].value == "")
    > {
    > alert("Please Select total Lecture Cunducted");
    > document.all['lecture_held'].focus();
    > valid = false;
    > }
    > if ( document.all['att'].value == "")
    > {
    > alert("Please Enter Students Attendance");
    > document.all['att'].focus();
    > valid = false;
    > }
    > return valid;
    >}
    >
    > when it returns false then it executes the jsp code...


    Highly improbable, since the JSP code would be running on the server,
    and the above javascript on the vlient.

    > what should i do so that when it return true then only it should
    > execute the jsp code....



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Mar 8, 2008
    #5
    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. André
    Replies:
    3
    Views:
    1,596
  2. DJ
    Replies:
    3
    Views:
    934
  3. Iñaki Baz Castillo
    Replies:
    9
    Views:
    196
    Igor Pirnovar
    Feb 26, 2009
  4. Randell D.
    Replies:
    4
    Views:
    149
    Randell D.
    Nov 27, 2003
  5. Replies:
    5
    Views:
    127
    Dr John Stockton
    Mar 2, 2005
Loading...

Share This Page