checkboxes adding values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sermed
    New Member
    • Dec 2008
    • 3

    checkboxes adding values

    please can anyone help me i dont know how to make a java script code

    i have multiple check boxes i want to assign every one a numeric value when the

    user checks the first box the value should appear and if he checks the second

    box the value is added to the value of the first check box and displayed and so on
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    please show what you have done so far ... even the html ... so that we have something to work with. and give a short example for what you want to achieve ... especially the exact output. what do you mean with 'added to'?

    kind regards

    Comment

    • sermed
      New Member
      • Dec 2008
      • 3

      #3
      thanks dear for reply
      this what i want to do i solve it thanks for u r help

      Code:
      <script type="text/javascript">
      	function checkTotal() {
      		document.listForm.total.value = '';
      		var sum = 0;
      		for (i=0;i<document.listForm.choice.length;i++) {
      		  if (document.listForm.choice[i].checked) {
      		  	sum = sum + parseInt(document.listForm.choice[i].value);
      		  }
      		}
      		document.listForm.total.value = sum;
      	}
      </script>
      
      <form name="listForm">
      <input type="checkbox" name="choice" value="2" onchange="checkTotal()"/>2<br/>
      <input type="checkbox" name="choice" value="5" onchange="checkTotal()"/>5<br/>
      <input type="checkbox" name="choice" value="10" onchange="checkTotal()"/>10<br/>
      <input type="checkbox" name="choice" value="20" onchange="checkTotal()"/>20<br/>
      Total: <input type="text" size="2" name="total" value="0"/>
      </form>
      Last edited by acoder; Dec 29 '08, 09:36 PM. Reason: Added [code] tags

      Comment

      • sermed
        New Member
        • Dec 2008
        • 3

        #4
        please help please with checkboxes adding

        hi,happy new year for all,,please i have a problem i have checkbox array each have a value i want that when each checkbox is check the overall sum is incremented this what is the wrong with this code?? please help

        Code:
        script type="text/javascript">
        	function checkTotal() {
        		document.listForm.total.value = '';
        		var sum = 0;
        		for (i=0;i<document.listForm.choice.length;i++) {
        		  if (document.listForm.choice[i].checked) {
        		  	sum = sum + parseFloat(document.listForm.choice[i].value);
        		  }
        		}
        		document.listForm.total.value = sum;
        	}
        </script>
        
        
        <form name="listForm"  >
        <TABLE cellPadding=3 width=600 border=0>
                
                
              
                <TR>
                  <TD >TEAK SIDE DECKS (2889)</TD>
                  <TD ><input  name="choice" value="2889" type="checkbox" onchange="checkTotal()" /></TD></TR>
        
                <TR>
                  <TD >LEAD DEEP KEEL (1825)</TD>
                  <TD><input  name="choice" value="1825" type="checkbox" onchange="checkTotal()"></TD></TR>
               
                <TR>
                  <TD >FULLY BATTENED MAINSAIL (558)</TD>
                  <TD><input  name="choice" value="558"  type="checkbox"  onchange="checkTotal()"></TD></TR>
               
                <TR>
                  <TD>HIGH TECH SAILS FOR CONVENTIONAL RIG (1979)</TD>
                  <TD ><input  name="choice" value="1979" type="checkbox" onchange="checkTotal()"></TD></TR></table></form>
        Last edited by gits; Jan 2 '09, 10:24 AM. Reason: added code tags

        Comment

        • RamananKalirajan
          Contributor
          • Mar 2008
          • 608

          #5
          Hello Sermed, instead of onchange use onclick, hope that will fix ur problem

          Regards
          Ramanan Kalirajan

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            yep ... the onchange just seems to work properly with FF and not IE ... so just use onclick as suggested ...

            PS: merged threads ... please don't double post your questions ... you may just bump it up by replying to your own post ...

            regards,
            MOD

            Comment

            Working...