/    Sign up×
Community /Pin to ProfileBookmark

Call Function within a Function (reusable code)?

Hi all,

I’m trying to call a function within a function, which I can do if I don’t need it to return false. But I need it to return false (if it is)…how? I want to have this search.js file to be “re-usable” by two different search pages:

[code]
//*********************************
//**** INITIAL SEARCH CRITERIA ****
//*********************************
function initialSearch(sCat) {
if (sCat == “_”) {
alert(“some alert.”);
search.sCat.focus();
return false;
}
return true;
}

//*******************************
//**** BASIC SEARCH CRITERIA ****
//this is called from search page 1
//*******************************
function searchBasic() {

var sCat = search.sCat.value;
initialSearch(sCat); //if initial check is false…don’t go into code below (right now it does)

if (search.sVar1.value==”_”) {
alert(“some alert”);
search.sVar1.focus();
return false;
}

if (search.sVar2.value==”_”) {
alert(“some alert.”);
search.sVar2.focus();
return false;
}
return true;
}

//***********************************
//**** ADVANCED SEARCH CRITERIA ****
//this is called from search page 2.
//***********************************
//work in progress…
function searchAdvanced() {

return initialSearch();

searchBasic(); //re-use basic logic if any in basic logic fails…return false out of all code.

//more complex checking in the works…

return true;
}
[/code]

Any ideas?

Thanks!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@batfinkMar 27.2004 — I have edited your function called searchBasic()

[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script language="javascript" type="text/javascript">
//*********************************
//**** INITIAL SEARCH CRITERIA ****
//*********************************
function initialSearch(sCat) {
if (sCat == "_") {
alert("some alert1");
document.search.sCat.focus();
return false;
}
return true;
}

//*******************************
//**** BASIC SEARCH CRITERIA ****
//this is called from search page 1
//*******************************
function searchBasic()
{

var sCat = document.search.sCat.value;
if(initialSearch(sCat)) //if initial check is false...don't go into code below (right now it does)
{
if (document.search.sVar1.value=="_")
{
alert("some alert2");
document.search.sVar1.focus();
return false;
}
if (document.search.sVar2.value=="_")
{
alert("some alert3");
search.sVar2.focus();
return false;
}
return true;
}
}

//***********************************
//**** ADVANCED SEARCH CRITERIA ****
//this is called from search page 2.
//***********************************
//work in progress...
function searchAdvanced() {

return initialSearch();

searchBasic(); //re-use basic logic if any in basic logic fails...return false out of all code.

//more complex checking in the works...

return true;
}

</script>
</head>
<body>
<form name="search">
<input type="text" name="sCat"><br>
<input type="button" value="SEARCH" onClick="searchBasic()"><br>
<input type="text" name="sVar1"><br>
<input type="text" name="sVar2"><br>
</form>
</body>
</html>
[/code]
×

Success!

Help @rxsid spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...