Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function calling function

Status
Not open for further replies.

muddunazar

Programmer
Jun 7, 2010
2
US
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;
}
}
 
You mean other than the fact that your function abc() will always return true? And thus the form will be submitted always.

Code:
function abc()
{
tableA();
tableB();
tableC();
[red]return true;[/red]
}

abc() returns true regardless of what the other 3 functions return, because you aren't catching whatever they return.

You want to return false if any of the 3 called functions return false.

So:

Code:
function abc()
{
if(tableA() && tableB() && tableC()){
[red]return true;[/red]
}
else{
[blue]return false;[/blue]
}
}

You coudl of course just do all the checking in a single function since your checking is so simple. But I digress.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks a lot vacunita. It helped to serve my purpose.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top