Jun
10
2013
10
2013
Sum values of all checked radio buttons
A snippet by admin
No Comments
//Sum the values of selected radio buttons and put into input
$('body').on('change', 'input', function(){
//Start the sum counter
var thisCount = parseInt(0);
//Run through all the selected radio buttons
var data = $.map($("input:radio:checked"), function(elem, idx) {
thisCount = + thisCount + parseInt( $(elem).val() );
$('#totals').val(thisCount);
});
});
//To Compile non integer data into a string
$('body').on('change', 'input', function(){
//Start the output
var thisValue = '';
//Run through all the selected radio buttons and join with spaces
var data = $.map($("input:radio:checked"), function(elem, idx) {
return thisValue + $(elem).val();
}).join(' ');
$('#totals').val(data);
});
Leave a comment
Recent Snippets
- htaccess : Only allow access to specific wordpress upload types if logged in
- MySQL : Query WordPress Database for Invalid Media Filenames
- PHP : Get Actual IP Address with PHP
- JavaScript : Allow Tab in Textarea
- PHP : Clean sanitized database contents on output
- htaccess : Force www. prefix in URIs
- PHP : Force File Download with Correct Content Type
- Wordpress : Disable upgrade notification