SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2003
    Location
    Ireland
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calling 2 Functions Problem

    Hi all, I have a form which I validate with two functions.

    I use an OnSubmit in the opening form tag to call both functions.

    <script type="text/javascript">
    function doBoth()
    {
    validate_Dir1();
    validate_Dir2();
    }
    </script>

    Seperately both functions work perfectly, however when called from doBoth(), one of my functions validates the form, indicates there is a field that needs to be filled in, but then jumps the user on to the next form to fill in. It should of course not have jumped to the next form as I had a 'return false;' statement in my code.

    Called on its own this function works correctly.

    Does anyone know what is causing this?

    Thanks

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps this is what you want.
    Code:
    function doBoth()
    {
      var out = validate_Dir1();
      if(out) out = validate_Dir2();
      return out;
    }
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kravvitz
    Perhaps this is what you want.
    Code:
    function doBoth()
    {
      var out = validate_Dir1();
      if(out) out = validate_Dir2();
      return out;
    }
    or just
    Code:
    function doBoth()
    {
      return validate_Dir1() && validate_Dir2();
    }

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorccu's method is better.

    I wonder why it didn't occur to me...
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2003
    Location
    Ireland
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies, but I'm still having problems with this.

    My second function never seems to get called. Individually they both work as expected.

    I've tried

    <script type="text/javascript">
    function doBoth()
    {
    return validate_director1() && validate_director2();
    }
    </script>

    and...

    <script type="text/javascript">
    function doBoth()
    {

    return validate_director1();
    return validate_director2();
    }
    </script>


    .only the first function ever gets called for some reason??

    Thanks

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2003
    Location
    Ireland
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As I outlined in my first post, if i use the following..

    <script type="text/javascript">
    function doBoth()
    {
    validate_director1();
    validate_director2();
    }
    </script>

    ...both my functions are called, but they don't stop/break when they come to a 'return false;' statement, it moves the user on to the next form for some reason.

    I call the function using onSubmit="return doBoth(); in the FORM tag.

    Regards
    Melt


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •