Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add the two value and then display it in a Total field 1

Status
Not open for further replies.

yogi564

Programmer
Oct 16, 2001
48
AU
hi all

Can somebody help me out. I need a code that will add two fields and then give me a total value in third and final field. It should allow users to input their own numbers as well as decimal point in the two fields to give the final value. thank's

from
yogi
 
hi

i put this example for you and it should work on both browsers.

note:
if you dont use the parseFloat method then you add the 2 elements as a string....

<HTML>
<HEAD>
<TITLE></TITLE>
<script language=&quot;javascript&quot;>
function add()
{
//here is one way of doing it: document.forms[&quot;myForm&quot;].num1.value
var n1 = parseFloat(document.forms[&quot;myForm&quot;].num1.value);
var n2 = parseFloat(document.forms[&quot;myForm&quot;].num2.value);

//here is another way of doing it:document.forms[0].
document.forms[0].sum.value = n1 + n2;
}
</script>
</HEAD>
<BODY BGCOLOR=&quot;#FFFFFF&quot; TEXT=&quot;#000000&quot; LINK=&quot;#0000FF&quot; VLINK=&quot;#800080&quot;>
<form name=&quot;myForm&quot; action=&quot;javascript:add()&quot;>
<input type=&quot;text&quot; name=&quot;num1&quot; value=&quot;num1&quot;><br>
<input type=&quot;text&quot; name=&quot;num2&quot; value=&quot;num2&quot;><br>
<input type=&quot;submit&quot; ><br>
<input type=&quot;text&quot; name=&quot;sum&quot; value=&quot;sum&quot;>
</form>

</BODY>
</HTML>
 
Hi raikyng

I s there a way of not using a submit button, but when you just enter the two specific field it should automatically give the sum value without pressing the submit button.

Thank's
From
yogi
 
Hi raikyng

Don't worry I work it out? Thank's for you help for the previous example
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top