Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Getting values from checkbox, add them, and display the result
- <div id="pakker">
- <input type="checkbox" value="39" />test 1<br/>
- <input type="checkbox" value="79" />test 2<br/>
- <input type="checkbox" value="29" />test 3<br/>
- <input type="checkbox" value="49" />test 4<br/>
- ect
- </div>
- var total = 0;
- $("#pakker input[type='checkbox']:checked").each(function() {
- total += parseInt(this.value, 10);
- });
- //Do whatever you like with total
- var result = 0;
- $("#pakker input:checked").each(function(){ result += $(this).val(); });
- alert(result );
- var sum = $('#pakker :checkbox:checked').map(function() {
- return parseInt(this.value, 10);
- }).get().reduce(function(prev, current) {
- return prev + current;
- }, 0);
- $(document).ready(function(){
- $("input[type='checkbox']").click(function(){
- var total = 0;
- $("#pakker input[type='checkbox']:checked").each(function() {
- total += parseInt(this.value, 10);
- });
- $('#result').html(total);
- });
- });
- <span id="result"></span>
- <div id="pakker">
- <input type="checkbox" value="39" />test 1 - value 39<br/>
- <input type="checkbox" value="79" />test 2 - value 79<br/>
- <input type="checkbox" value="29" />test 3 - value 29<br/>
- <input type="checkbox" value="49" />test 4 - value 49<br/>
- ect
- </div>
Add Comment
Please, Sign In to add comment