Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    combining two functions (first one calls the other)


    This is the first function.


    Code:
    <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.

    Code:
    <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 !!!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,727
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •