Lunes, Marso 7

Javascript:Autosum Code

Here's the code. The first part is its HTML code. Be sure to put it in a form.
Then add this attribute onfocus="startCalc();" in your texboxes that you want to add their values except for the textbox where you want to display the result.

<form method="post" name="autosum"> <input id="first" name="first" onblur="stopCalc();" onfocus="startCalc();" size="3" type="text" /><input id="second" name="second" onblur="stopCalc();" onfocus="startCalc();" size="3" type="text" /><input id="total" name="total" onblur="stopCalc();" onfocus="startCalc();" readonly="true" size="8" type="text" /></form>

Then paste this javascript code on the last part of your page. Done!!!
<script type="text/javascript"> function startCalc(){ interval = setInterval("calc()",1); } function calc(){ one = document.autosum.first.value; two = document.autosum.second.value; document.autosum.total.value = (one * 1) + (two * 1); } function stopCalc(){ clearInterval(interval); } </script>

0 comments:

Mag-post ng isang Komento

 
Powered by Blogger