savin

01-28-2006, 07:31 PM

I am running into a small problem with javascript functions. I'm obviously doing something stupid probably because of my background in other programming languages.

My problem is the function does not seem to be returning the values. I have recreated the problem in a very small page. I have 5 global variables x1, x2, x3, x4 and x5 and three local variables in the function g1, g2, g3, g4 and g5 and g4 and g5 don't seem to be returned since x4 and x5 remain unchanged.

***************

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>Untitled</title>

<script type="text/javascript">

var x1 = 5;

var x2 = 6;

var x3 = 7;

var x4 = 8;

var x5 = 9;

function do_calcs() {

CalcNorms(x1, x2, x3, x4, x5);

}

function CalcNorms(g1, g2, g3, g4, g5) {

alert("passed g4 and g5 values = " + g4 + " and " + g5);

g4 = g1 * g2 * g3;

g5 = g1 + g2 + g3;

alert("calculated g4 and g5 values = " + g4 +" and " + g5);

}

</script>

</head>

<body>

<script language=Javascript type="Text/Javascript">

do_calcs();

alert("returned x4 and x5 values = " + x4 +" and " + x5);

</script>

</body>

</html>

What am I doing wrong?

Any help would be much appreciated.

My problem is the function does not seem to be returning the values. I have recreated the problem in a very small page. I have 5 global variables x1, x2, x3, x4 and x5 and three local variables in the function g1, g2, g3, g4 and g5 and g4 and g5 don't seem to be returned since x4 and x5 remain unchanged.

***************

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>Untitled</title>

<script type="text/javascript">

var x1 = 5;

var x2 = 6;

var x3 = 7;

var x4 = 8;

var x5 = 9;

function do_calcs() {

CalcNorms(x1, x2, x3, x4, x5);

}

function CalcNorms(g1, g2, g3, g4, g5) {

alert("passed g4 and g5 values = " + g4 + " and " + g5);

g4 = g1 * g2 * g3;

g5 = g1 + g2 + g3;

alert("calculated g4 and g5 values = " + g4 +" and " + g5);

}

</script>

</head>

<body>

<script language=Javascript type="Text/Javascript">

do_calcs();

alert("returned x4 and x5 values = " + x4 +" and " + x5);

</script>

</body>

</html>

What am I doing wrong?

Any help would be much appreciated.