SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function calling function returning false.

    I am trying to write a function that is being invoked when some one clicks the submit button on the form.
    <form name="sectionA" action="optionpage.cfm" onSubmit="return abc()">

    I have three tables with initials textboxes. I want to check if they are empty and return false(stay on the same page), else go to action page.

    Here is what I am doing, I Created three functions tableA(), tableB(),tableC() call them from function abc(). These functions tableA(), tableB(), tableC() return false if one of the field is empty and stop furthur processing and remain in the same page. If none(errors), then go the other page.
    i.e if table B has empty fields, page should stop furthur processing and remain in the same page.
    Here is how I am doing it
    Can somebody please point out what I am doing wrong here.
    Even when there is empty field, the code moves me to the actionPage.


    function abc()
    {
    tableA();
    tableB();
    tableC();
    return true;
    }

    function tableA()
    {
    if(""=document.formName.tableAinitial.value)
    return false;
    }else{
    return;
    }
    }


    function tableB()
    {
    if(""=document.formName.tableBinitial.value)
    return false;
    }else{
    return;
    }
    }

    function tableC()
    {
    if(""=document.formName.tableCinitial.value)
    return false;
    }else{
    return;
    }
    }

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function tableA()
    {
    if(""=document.formName.tableAinitial.value)
    return false;
    }else{
    return;
    }
    }
    In this function the test conditon is not performing a comparison and also must be generating an error:

    https://developer.mozilla.org/en/Cor...ison_Operators

    In addition to which it returns either true or undefined instead of true or false.


    Code:
    function abc()
    {
    tableA();
    tableB();
    tableC();
    return true;
    }
    This function returns true unconditionally, not reading the values returned by the functions it calls.
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Ali for your response. It helped me resolve my issue.


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
  •