1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

javascript onclick

Discussion in 'JavaScript' started by wordlinkz, Jul 31, 2007.

  1. #1
    Hello

    I have a form in which i want to call 3 functions when the button is pressed...
    if one returns false i want all the functions to quit and display the error generated by the false returning function.

    Will all the functions i call return false if one returns false how do i do this?
    In short i dont want the form to continue if one function returns false

    Could someone share the code how it will be:

    <button type="button" name="B2"
    onclick="URLform.target='_parent';URLform.submit()">
    Accept Terms</button>

    How will i do the returning false and true part?
     
    wordlinkz, Jul 31, 2007 IP
  2. disco_danny

    disco_danny Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Let me know if I am not understanding the situation, but it sounds like you need to call a single function that wraps your three functions. Something like this -

    function formSubmit()
    {
    //set gobal boolean
    allIsWell = true;

    allIsWell = functionOne();

    if (allIsWell)
    allIsWell = functionTwo();

    if (allIsWell)
    allIsWell = functionThree();

    //finally if everything run correctly submit the form
    if (allIsWell)
    document.URLform.submit();
    }

    function functionOne()
    {
    //if based on some condition you need to return false
    alert('Some Message');
    return false;
    //else
    return true;
    }

    function functionTwo()
    {
    //if based on some condition you need to return false
    alert('Some Message');
    return false;
    //else
    return true;
    }

    function functionThree()
    {
    //if based on some condition you need to return false
    alert('Some Message');
    return false;
    //else
    return true;
    }


    Hope this was helpful
     
    disco_danny, Jul 31, 2007 IP