Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <input type="text" id="field_results"/><br>
- <input type="checkbox" value="1">1<br>
- <input type="checkbox" value="2">2<br>
- <input type="checkbox" value="3">3
- $(document).ready(function(){
- $(":checkbox").on('click', function() {
- if($(':checkbox:checked')) {
- var fields = $(":checkbox").val();
- jQuery.each( fields, function( i, field ) {
- $('#field_results').val($('#field_results').val() + field.value + " ");
- });
- }
- });
- });
- $(document).ready(function(){
- $checks = $(":checkbox");
- $checks.on('click', function() {
- var string = $checks.filter(":checked").map(function(){
- return this.value;
- }).get().join(" ");
- $('#field_results').val(string);
- });
- });
- $(document).ready(function(){
- $("input:checkbox").click(function() {
- var output = "";
- $("input:checked").each(function() {
- output += $(this).val() + " ";
- });
- $("#field_results").val(output.trim());
- });
- });
- if($(':checkbox:checked')) {
- var fields = $(":checkbox").val();
- $(":checkbox").on('change', function() {
- var total = [];
- $(':checkbox:checked').each( function(){ //find the checked checkboxes and loop through them
- total.push(this.value); //add the values to the array
- });
- $('#field_results').val(total.join(" ")); //join the array
- });
- $(":checkbox").on('click', function () {
- var fields = '';
- $(":checkbox").each(function () {
- if (this.checked) {
- fields += $(this).val() + ' ';
- }
- });
- $('#field_results').val($.trim(fields));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement