AutoSum Generation JavaScript

This javascript will help you to generate the autosum when changes made in the checkbox.

Features

  • You can generate the sum when changes made in the checkbox using javascript
  • Simple and ease of use.
  • Just copy the code into your page and use it.

Preview


Value1
Value2
Value3
Result  
©hscripts.com

Downloads

Javascript

<!--Script by hscripts.com-->
<!--More scripts @ https://www.hscripts.com-->
<script type="text/javascript">
var a=10; //set the value of first textbox.
var b=20; //set the value of second textbox.
var c=30; //set the value of third textbox.
function app()
{
if(frm.chk1.checked==true)
frm.txt.value=a;
else
frm.txt.value=0;
if(frm.chk2.checked==true)
frm.txt1.value=b;
else
frm.txt1.value=0;
if(frm.chk3.checked==true)
frm.txt2.value=c;
else
frm.txt2.value=0;
var sum;
if(frm.chk1.checked || frm.chk2.checked || frm.chk3.checked==true)
{
x=parseInt(frm.txt.value);
y=parseInt(frm.txt1.value);
z=parseInt(frm.txt2.value);
sum=x+y+z;
frm.txt3.value=sum;
}
else
frm.txt3.value=0;
}
</script>
<!--Script by hscripts.com-->

HTML Code


<!--Script by hscripts.com-->
<form name="frm">
<table style="border:solid green 1px">
  <tr><td>Value1<input type="text" name="txt"><input type="checkbox" name="chk1" onClick="app()"></td></tr>
  <tr><td>Value2<input type="text" name="txt1"><input type="checkbox" name="chk2" onClick="app()"></td></tr>
  <tr><td>Value3<input type="text" name="txt2"><input type="checkbox" name="chk3" onClick="app()"></td></tr>
  <tr><td>Result<input type="text" name="txt3" READONLY></td></tr>
  <tr><td align=center>&copy<a href="https://www.hscripts.com" style="color:#3D366F;text-decoration:none;cursor:pointer;font-size:13px">hscripts.com</a></td></tr></table>
</form>
<!--Script by hscripts.com-->

  • Release Date - 07-04-2008
  • Get free version without ©copyright link for just $10/-
  • For customization of this script or any script development, mail to support@hscripts.com

Usage

  • This script is useful for generating the autosum if you click the checkbox.
  • The function app() is called to assign the value to the text box. If you click the checkbox the value will be assigned and then added. The result will be displayed in the result field.
  • To Set the values of textbox, just change the value of variables.
  • Example: var a=10;//set value of first textbox. 
  • Copy the code into your page and use it.

License

Related Scripts

Free Javascript Scripts


Ask Questions

Ask Question