Click to See Complete Forum and Search --> : calculations


lhsths
01-22-2003, 09:21 AM
I have an edit box in which i write a number (e.g 50). In another i have the number(e.g 5) and in another the number (e.g.3). By pressing a button the value 42 will appear(50 - 5 - 3 = 42)in another edit box. Always subtracting from the first edit box.

I know that i must use the function recalc() but since i am new i have some difficulties.

Can anyone please make my life easier :(

Dan Drillich
01-22-2003, 09:45 AM
Please try -


<SCRIPT LANGUAGE="JavaScript">

function sub(r,p1,p2){
r.value = parseInt(p1) - parseInt(p2);
}

</SCRIPT>


<FORM name="formx">
<p align="left">My total is
<input type=text size=10 value=50 name="a">

</p>
<p align="left">Please substract:
<input type "number" value=0 name="b" size=10>
<input type="button" value=" Calculate "
onClick="sub(document.formx.a,document.formx.a.value,document.formx.b.value);" name="button">
</p>

</FORM>

Pretty close.

Cheers,
Dan

Dan Drillich
01-22-2003, 10:02 AM
and a bit cleaner -


<SCRIPT LANGUAGE="JavaScript">

function sub(p1,p2){
return parseInt(p1) - parseInt(p2);
}

</SCRIPT>




<FORM name="formx">
<p align="left">My total is
<input type=text size=10 value=50 name="a">

</p>
<p align="left">Please substract:
<input type "number" value=0 name="b" size=10>
<input type="button" value=" Calculate " onClick="a.value=sub(a.value,b.value);" name="button">
</p>

</FORM>


Cheers,
Dan