Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <input type="text" id="field_results"/><br>
  2.  
  3. <input type="checkbox" value="1">1<br>
  4. <input type="checkbox" value="2">2<br>
  5. <input type="checkbox" value="3">3
  6.  
  7.  
  8. $(document).ready(function(){
  9. $(":checkbox").on('click', function() {
  10. if($(':checkbox:checked')) {
  11. var fields = $(":checkbox").val();
  12. jQuery.each( fields, function( i, field ) {
  13. $('#field_results').val($('#field_results').val() + field.value + " ");
  14. });
  15. }
  16. });
  17. });
  18.  
  19. $(document).ready(function(){
  20. $checks = $(":checkbox");
  21. $checks.on('click', function() {
  22. var string = $checks.filter(":checked").map(function(){
  23. return this.value;
  24. }).get().join(" ");
  25. $('#field_results').val(string);
  26. });
  27. });
  28.  
  29. $(document).ready(function(){
  30. $("input:checkbox").click(function() {
  31. var output = "";
  32. $("input:checked").each(function() {
  33. output += $(this).val() + " ";
  34. });
  35.  
  36. $("#field_results").val(output.trim());
  37.  
  38. });
  39. });
  40.  
  41. if($(':checkbox:checked')) {
  42.  
  43. var fields = $(":checkbox").val();
  44.  
  45. $(":checkbox").on('change', function() {
  46. var total = [];
  47. $(':checkbox:checked').each( function(){ //find the checked checkboxes and loop through them
  48. total.push(this.value); //add the values to the array
  49. });
  50. $('#field_results').val(total.join(" ")); //join the array
  51. });
  52.  
  53. $(":checkbox").on('click', function () {
  54. var fields = '';
  55. $(":checkbox").each(function () {
  56. if (this.checked) {
  57. fields += $(this).val() + ' ';
  58. }
  59. });
  60. $('#field_results').val($.trim(fields));
  61. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement