I found this example:
The Idea is to get the checked checkbox value, and use it further as avariable:
Maybe this example is not the best, but I only found this one as it is much closer to what I want.
See FIDDLE
<div id="pakker">
<input type="checkbox" checked="checked" 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/>
<script type="text/javascript">
jQuery(document).ready(function($) {
var sum = 0;
$('#pakker :checkbox').click(function() {
sum = 0;
$('#pakker :checkbox:checked').each(function(idx, elm) {
sum += parseInt(elm.value, 10);
});
$('#sum').html(sum);
});
});
</script>
As you can see it shows values only after mouse click checkbox. How can I make it to get the checked checkbox value on Loading page? Example: http://jsfiddle.net/vaKWs/31/
if more then one checkbox is selected it ADDS the numbers. is it possible to show the valuse like (93, 25, 256 etc) without adding them?
Is it possible the result to put into a VARIABLE so that i can use this variable in other functions on the page? For example if $variable { then } esle {...
* PS * I am new with php and js. Thank you for understanding!
jQuery(document).ready(function($) {
var sum = 0;
$('#pakker :checkbox').click(function() {
sum = 0;
$('#pakker :checkbox:checked').each(function(idx, elm) {
sum += parseInt(elm.value, 10);
});
$('#sum').html(sum);
});
$('#pakker :checkbox[checked]').each(function(idx, elm){
sum += parseInt(elm.value, 10);
});
$('#sum').html(sum);
});
in HTML:
<input type="checkbox" checked value="39" />test 1<br/>
There you go.
Please rate my answer.
that would really help me!!
already answered
You use a sum of the values, if you want them as separate text: sum += parseInt(elm.value, 10) + " "
should do it. This forces a space between keeping them as a text string.
The example you have saves them into a variable already. Check out arrays for storing them into individual variables
Hope that helps
Actually @Jose makes a lot of sense to me. i felt exactly like you before. but with of a lot of learning i manage to create nice sites. let me help you on 3:
if you assign a varible at the top of the page like that HTML:
<script>
myNewVar = new Array();
//... rest of the script
</script>
so that variable is available to all scripts around..