...

View Full Version : combining two functions (first one calls the other)



killykilly
12-13-2010, 08:45 PM
This is the first function.


<html>
<head>
</head>
<body>


<script language="javascript" type="text/javascript">

function getthat****(){
num_a=Number(document.addition.entry_1.value);
num_b=Number(document.addition.entry_2.value);
num_c=Number(document.addition.entry_3.value);
num_d=Number(document.addition.entry_4.value);
num_e=Number(document.addition.entry_5.value);



valNum1=num_a*num_c
valNum2=num_a*num_d
valNum3=num_b*num_c
valNum4=num_b*num_d

valNum5=valNum1-valNum4
valNum6=valNum2+valNum3

valNum7=num_e/Math.sqrt(3)
valNum8=valNum7+valNum1-valNum4

document.addition.endVal1.value=valNum8;
document.addition.endVal2.value=valNum6;
}

</script>


<form name="addition">

<br>
impedance (rectangular)
<input type="text" name="entry_1"> + j
<input type="text" name="entry_2"> ohms
<br>
<br>

line current (rectangular)
<input type="text" name="entry_3"> + j
<input type="text" name="entry_4"> amperes<br><br>
<br>
<br>

line value of receiving voltage
<input type="text" name="entry_5"> volts (angle is zero degrees) (reference)

<br>
<br>


(<input type="text" name="endVal1"> + j
<input type="text" name="endVal2">) Volts
<br>

<input type="button" value="Product" onclick="getthat****()">
<input type="reset" value="Clear">
</form>
</body>
</html>







And this is the second one.


<html>
<head>
</head>
<body>
<script language="javascript" type="text/javascript">

function PolarConvert(){
num_1=Number(document.addition.entry_1.value);
num_2=Number(document.addition.entry_2.value);



valNum1=Math.pow(num_1,2);
valNum2=Math.pow(num_2,2);
valNum3=Math.sqrt(valNum1 + valNum2);

valNum4=Math.atan(num_2/num_1);
valNum5=(valNum4*180)/Math.PI;
document.addition.endVal.value=valNum3;
document.addition.endVal2.value=valNum5;
}

</script>
<form name="addition">
<input type="text" name="entry_1">+ j
<input type="text" name="entry_2"> =
<input type="text" name="endVal"> angle
<input type="text" name="endVal2"><br>
<input type="button" value="Convert to polar" onclick="PolarConvert()">
<input type="reset" value="Clear">
</form>
</body>
</html>






The question is how do I combine these given that the value that would be computed in function 2 is already computed in function 1 ?


Thanks a lot !!!

Philip M
12-13-2010, 09:54 PM
I have no clue what that means, but

a) to call another function simply place
PolarConvert() in the first function.
or if you want to return a value:-
var retVal = return.PolarConvert();
with at the end of the function
document.addition.endVal2.value=valNum5;
return valNum5;

b) Whatever this is intended to do it is bogus, as Old Pedant would say:-
(<input type="text" name="endVal1"> + j
<input type="text" name="endVal2">) Volts


Quizmaster: Which Mikhail was the last President of the Soviet Union?
Contestant: Lenin. Mikhail Lenin.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum