radio button - Remove ".00" from Simple Calculation via JavaScript -


i'm working on simple form calculation sums whole numbers onclick.

the problem script calculates money appends .00 @ end. don't want decimal positions.

i not @ javascript wondering how remove ".00"

i need whole number no decimals.

my gut is has ['set' + (i++)] i'm not 100% sure on that.

<head> <title>untitled</title> <style type="text/css">  fieldset {     float: left;     width: 60px;     padding: 5px;     margin-right: 4px; } legend {     font-weight: bold; } #total {     font-size: 11px;     width: 40px; }  </style> <script type="text/javascript">  function setradios() {     function sumradios()     {         var total = 0, = 1, oform = this.form;         while (radgrp = oform.elements['set' + (i++)])         {             j = radgrp.length;                             if (radgrp[--j].checked)                 {                     total += number(radgrp[j].value);                     break;                 }             while (j);         }         oform.elements.total.value = total.tofixed(2);     }      var = 0, input, inputs = document.getelementbyid('f1').getelementsbytagname('input');     while (input = inputs.item(i++))         if (input.name.match(/^set\d+$/))             input.onclick = sumradios; }  onload = setradios;  </script> </head> <body> <form id="f1"> <fieldset>  <legend>set 1</legend> <input id="r1" type="radio" name="set1" value="5" /><label for="r1">5</label><br /> <input id="r2" type="radio" name="set1" value="10" /><label for="r2">10</label><br /> <input id="r3" type="radio" name="set1" value="15" /><label for="r3">15</label> </fieldset> <fieldset>  <legend>set 2</legend> <input id="r4" type="radio" name="set2" value="10" /><label for="r4">10</label><br /> <input id="r5" type="radio" name="set2" value="15" /><label for="r5">15</label><br /> <input id="r6" type="radio" name="set2" value="25" /><label for="r6">25</label> </fieldset> <fieldset>  <legend>set 3</legend> <input id="r7" type="radio" name="set3" value="1" /><label for="r7">1</label><br /> <input id="r8" type="radio" name="set3" value="9" /><label for="r8">9</label><br /> <input id="r9" type="radio" name="set3" value="24" /><label for="r9">24</label> </fieldset>  <fieldset style="position:relative;top:36px;width:140px;"> <input id="total" type="text" name="total" value="" /><strong> total</strong>&nbsp;&nbsp; <input type="reset" style="font-size:11px;" /> </fieldset>  </form> </body> </html> 

replace:

total.tofixed(2); 

with:

total.tofixed(0); 

or use parseint

or, since inputs ints start with, can leave out tofixed out altogether.

see here more on tofixed


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -