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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a Function

Status
Not open for further replies.

hiyatran

Technical User
Aug 7, 2010
21
CA
I would like to call a function within a function. Is this even possible??
When I do this I get "undefined"

Here's my code:
Code:
<html>
<head>
<script type="text/javascript">
function product(a,b){
   total = a*b;
   display(total);
}

function display(num){
   return num;
}
</script>
</head>

<body>
<h1>This text I do NOT want to be erased.</h1>

<a href="[URL unfurl="true"]http://google.com"[/URL] target="_blank">Total: </a>
<script type="text/javascript">
product(3,4);
document.write(display());
</script>

</body>
</html>

I know you can just return in the first function, "product()" but I would like to do something else in my second function "display()" then return a value.

thanks

 
I don't follow.
You have your display function inside your product function. So that would execute product function which multiplies your passed values, and at the end call the display function to do something else with that value.

Can you explain a bit more what it is you want to do?






----------------------------------
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.
 
Hi

In the function declaration you promised to display() it will get a parameter when called. Then you gave it nothing. That is called [tt]undefined[/tt] in JavaScript. Give it the parameter it expects :
JavaScript:
document[teal].[/teal][COLOR=darkgoldenrod]write[/color][teal]([/teal][COLOR=darkgoldenrod]display[/color][teal]([/teal][COLOR=darkgoldenrod]product[/color][teal]([/teal][purple]3[/purple][teal],[/teal][purple]4[/purple][teal])));[/teal]


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top