Click here to Skip to main content
15,070,139 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hey, hope someone could help. I tried to use other functions value inside a function, but unsuccessful.

What I have tried:

Here what I have done:

    <td><input type="text" name="r1" id="r1" onkeyup="total_r1()" class="form-control"/></td>
    <td><input type="text" name="s1" id="s1" onkeyup="total_r1()" class="form-control"/></td>
    <td><input type="text" name="t1" id="t1" value="" class="form-control"/></td>
    <td><input type="text" name="r2" id="r2" onkeyup="total_r2()" class="form-control"/></td>
    <td><input type="text" name="s2" id="s2" onkeyup="total_r2()" class="form-control"/></td>
    <td><input type="text" name="t2" id="t2" class="form-control"/></td>
    <td><input type="text" name="r3" id="r3" onkeyup="total_r3()" class="form-control"/></td>
    <td><input type="text" name="s3" id="s3" onkeyup="total_r3()" class="form-control"/></td>
    <td><input type="text" name="t3" id="t3" class="form-control"/></td>
    <td><input type="text" name="r4" id="r4" onkeyup="total_r4()" class="form-control"/></td>
    <td><input type="text" name="s4" id="s4" onkeyup="total_r4()" class="form-control"/></td>
    <td><input type="text" name="t4" id="t4" class="form-control"/></td>
    <td  style="text-align:center;padding-top:1.5%">TOTAL</td>
    <td style="text-align:center;">
    	<input type="text" name="total_monthclaim" id="total_monthclaim" class="form-control"/>

here is my script:

function total_r1(){
    		var r1 = document.getElementById('r1').value;
    		var s1 = document.getElementById('s1').value;
    		var total = (r1*s1);
    		var t_1 = total.toFixed(2);
    		var t1 = document.getElementById('t1');
    		t1_5.value = t_1;
    	function total_r2(){
    		var r2 = document.getElementById('r2').value;
    		var s2 = document.getElementById('s2').value;
    		var total = (r2*s2);
    		var t_2 = total.toFixed(2);
    		var t2 = document.getElementById('t2');
    		t2.value = t_2;
    	function total_r3(){...}

        function total_r4(...){}

    	function total_all(){
    		var t1 = total_r1();
    		var t2 = total_r2();
    		var t3 = total_r3();
    		var t4 = total_r4();
    		var total = (t1+t2+t3+t4);
    		var totalclaim = total.toFixed(2);
    		var total_monthclaim = document.getElementById('total_monthclaim');
    		total_monthclaim.value = totalclaim;

What I want is for the
to total up all the value from other function and sent it to
<input id="total_monthclaim">
Updated 20-Aug-21 22:38pm

1 solution

You need to return the relevant values from each of your functions: JavaScript return Statement[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900