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

getting calculated value from another function

Status
Not open for further replies.

rshandy

Technical User
Dec 26, 2003
91
US
Can anyone tell me how retrieve a calculated value of a variable from another function:

Sorry for the silly example but:

<head>

<SCRIPT LANGUAGE="JavaScript">
var estimate = 0;

function total1 (){
estimate = 55;
}

function revisedtotal2 () {

estimate = estimate + 25;

}
</script>
</head>

<body>
<script language="JavaScript1.2">total1();</script>

<a href='javascript:revisedtotal2();'><img name="mw_1622_sw" src="graphics/mw_1622_sw.jpg" width="75" height="64" border="0"></a>
</body>

Obviously, after I call the revisedtotal2 function I want the value of estimate = 80.


Thanks,

Rich
 
Hello Rich..
I just modified a bit your HTML page
like this
<a href='javascript:revisedtotal2();alert(estimate)'>
and the alert gave me 80.
Would you please give more details of your problem ?

Good Luck!
Stef
 
Try this instead:

var estimate = 0;

function total1 (){
estimate1 = 55;
estimate2 = estimate1 + 25;
}

and remember that you have to call total1 now.

staffa

 
Sorry. I ment:

var estimate = 0;

function total1 (){
estimate = 55;
estimate2 = estimate1 + 25;
}
 
Sorry again. I'm pretty tired. This should work.

var estimate = 0;

function total1 (){
estimate = 55;
estimate1 = estimate + 25;
alert(estimate1);
}
 
<html>
<head>

<SCRIPT LANGUAGE="JavaScript">
var estimate = 0;

function total1 ()
{
estimate = 55;
return estimate;
}

function revisedtotal2 ()
{

var tot1 = total1();

estimate = tot1 + 25;

alert(estimate );

}
</script>
</head>

<body onLoad="revisedtotal2();">

</body>
</html>
 
To 4345487:

I'ts not necessary with all the functions.
Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var estimate = 0;

function total1 (){
estimate = 55;
estimate1 = estimate + 25;
alert(estimate1);
}
</script>
</head>
<body onLoad="total1();">
</body>
</html>
That is enought to get it to work.

staffa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top