Display value of checked check boxes javascript












0















Here I have written a javascript which selects all checkboxes on checking one checkbox and I want to display all the checked checkboxes value on button click. here it does selectall function correctly(ie. it selects all checkboxes). I am new to javascript and I need some help to display all the checked check box values, can any any one provide me the code to select all checkbox by clicking on a check box and display values of only selected checkboxes in a single function using javascript only...



Here is the javascript code



<script>
var checked=false;
function checkedAll ()
{
var c = document.getElementsByName("viju");
checked = document.getElementById('causelist_month').checked;

for (var i =0; i < c.length; i++)
{
c[i].checked=checked;
}
}
</script>


Here the HTML code



 <input type="checkbox" name="causelist_month" id="causelist_month" onclick="checkedAll ();">select all/unselect all
<input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
<input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
<input type="Button" value="Show values" onClick="checkedAll(this.value)"/>









share|improve this question

























  • you really should not be using the same ID for multiple elements within your HTML. I suggest you change your ID's to more meaningful ID's such as "jan" or "feb".

    – JosephGarrone
    Mar 10 '14 at 5:28











  • Loop over the collection of checkboxes, if item[i].checked then it's checked so push the value into an array (or some other storage object).

    – RobG
    Mar 10 '14 at 5:30











  • @Asryael—or remove the IDs completely, they aren't necessary.

    – RobG
    Mar 10 '14 at 5:30













  • @RobG that is correct, however I am unsure if he may or may not be using those ID's else where in the program.

    – JosephGarrone
    Mar 10 '14 at 5:31
















0















Here I have written a javascript which selects all checkboxes on checking one checkbox and I want to display all the checked checkboxes value on button click. here it does selectall function correctly(ie. it selects all checkboxes). I am new to javascript and I need some help to display all the checked check box values, can any any one provide me the code to select all checkbox by clicking on a check box and display values of only selected checkboxes in a single function using javascript only...



Here is the javascript code



<script>
var checked=false;
function checkedAll ()
{
var c = document.getElementsByName("viju");
checked = document.getElementById('causelist_month').checked;

for (var i =0; i < c.length; i++)
{
c[i].checked=checked;
}
}
</script>


Here the HTML code



 <input type="checkbox" name="causelist_month" id="causelist_month" onclick="checkedAll ();">select all/unselect all
<input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
<input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
<input type="Button" value="Show values" onClick="checkedAll(this.value)"/>









share|improve this question

























  • you really should not be using the same ID for multiple elements within your HTML. I suggest you change your ID's to more meaningful ID's such as "jan" or "feb".

    – JosephGarrone
    Mar 10 '14 at 5:28











  • Loop over the collection of checkboxes, if item[i].checked then it's checked so push the value into an array (or some other storage object).

    – RobG
    Mar 10 '14 at 5:30











  • @Asryael—or remove the IDs completely, they aren't necessary.

    – RobG
    Mar 10 '14 at 5:30













  • @RobG that is correct, however I am unsure if he may or may not be using those ID's else where in the program.

    – JosephGarrone
    Mar 10 '14 at 5:31














0












0








0


1






Here I have written a javascript which selects all checkboxes on checking one checkbox and I want to display all the checked checkboxes value on button click. here it does selectall function correctly(ie. it selects all checkboxes). I am new to javascript and I need some help to display all the checked check box values, can any any one provide me the code to select all checkbox by clicking on a check box and display values of only selected checkboxes in a single function using javascript only...



Here is the javascript code



<script>
var checked=false;
function checkedAll ()
{
var c = document.getElementsByName("viju");
checked = document.getElementById('causelist_month').checked;

for (var i =0; i < c.length; i++)
{
c[i].checked=checked;
}
}
</script>


Here the HTML code



 <input type="checkbox" name="causelist_month" id="causelist_month" onclick="checkedAll ();">select all/unselect all
<input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
<input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
<input type="Button" value="Show values" onClick="checkedAll(this.value)"/>









share|improve this question
















Here I have written a javascript which selects all checkboxes on checking one checkbox and I want to display all the checked checkboxes value on button click. here it does selectall function correctly(ie. it selects all checkboxes). I am new to javascript and I need some help to display all the checked check box values, can any any one provide me the code to select all checkbox by clicking on a check box and display values of only selected checkboxes in a single function using javascript only...



Here is the javascript code



<script>
var checked=false;
function checkedAll ()
{
var c = document.getElementsByName("viju");
checked = document.getElementById('causelist_month').checked;

for (var i =0; i < c.length; i++)
{
c[i].checked=checked;
}
}
</script>


Here the HTML code



 <input type="checkbox" name="causelist_month" id="causelist_month" onclick="checkedAll ();">select all/unselect all
<input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
<input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
<input type="Button" value="Show values" onClick="checkedAll(this.value)"/>






javascript checkbox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 11 '17 at 9:45









Chris Martin

23.9k451110




23.9k451110










asked Mar 10 '14 at 5:26









VIJUVIJU

9227




9227













  • you really should not be using the same ID for multiple elements within your HTML. I suggest you change your ID's to more meaningful ID's such as "jan" or "feb".

    – JosephGarrone
    Mar 10 '14 at 5:28











  • Loop over the collection of checkboxes, if item[i].checked then it's checked so push the value into an array (or some other storage object).

    – RobG
    Mar 10 '14 at 5:30











  • @Asryael—or remove the IDs completely, they aren't necessary.

    – RobG
    Mar 10 '14 at 5:30













  • @RobG that is correct, however I am unsure if he may or may not be using those ID's else where in the program.

    – JosephGarrone
    Mar 10 '14 at 5:31



















  • you really should not be using the same ID for multiple elements within your HTML. I suggest you change your ID's to more meaningful ID's such as "jan" or "feb".

    – JosephGarrone
    Mar 10 '14 at 5:28











  • Loop over the collection of checkboxes, if item[i].checked then it's checked so push the value into an array (or some other storage object).

    – RobG
    Mar 10 '14 at 5:30











  • @Asryael—or remove the IDs completely, they aren't necessary.

    – RobG
    Mar 10 '14 at 5:30













  • @RobG that is correct, however I am unsure if he may or may not be using those ID's else where in the program.

    – JosephGarrone
    Mar 10 '14 at 5:31

















you really should not be using the same ID for multiple elements within your HTML. I suggest you change your ID's to more meaningful ID's such as "jan" or "feb".

– JosephGarrone
Mar 10 '14 at 5:28





you really should not be using the same ID for multiple elements within your HTML. I suggest you change your ID's to more meaningful ID's such as "jan" or "feb".

– JosephGarrone
Mar 10 '14 at 5:28













Loop over the collection of checkboxes, if item[i].checked then it's checked so push the value into an array (or some other storage object).

– RobG
Mar 10 '14 at 5:30





Loop over the collection of checkboxes, if item[i].checked then it's checked so push the value into an array (or some other storage object).

– RobG
Mar 10 '14 at 5:30













@Asryael—or remove the IDs completely, they aren't necessary.

– RobG
Mar 10 '14 at 5:30







@Asryael—or remove the IDs completely, they aren't necessary.

– RobG
Mar 10 '14 at 5:30















@RobG that is correct, however I am unsure if he may or may not be using those ID's else where in the program.

– JosephGarrone
Mar 10 '14 at 5:31





@RobG that is correct, however I am unsure if he may or may not be using those ID's else where in the program.

– JosephGarrone
Mar 10 '14 at 5:31












4 Answers
4






active

oldest

votes


















0














Jsfiddle http://jsfiddle.net/2UFdc/



HTML



<form>
<input type="checkbox" name="causelist_month" id="causelist_month" onclick="checkedAll ();">select all/unselect all
<input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
<input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
<input type="Button" value="Show values" onClick="showVal(this.form)"/>
</form>


Javascript



var checked = false;

function checkedAll() {
var c = document.getElementsByName("viju");
checked = document.getElementById('causelist_month').checked;

for (var i = 0; i < c.length; i++) {
c[i].checked = checked;
}
}

function showVal(frm) {
var arr = ;
for (var i in frm.viju) {
if (frm.viju[i].checked) {
arr.push(frm.viju[i].value);
}
}
alert(arr);
return arr
}





share|improve this answer































    0














    First, use the event listener for the checkboxes rather than onClick:



    document.getElementById("causelist_month").addEventListener('change', function(){
    checkboxes = document.getElementsByName("viju");
    for( var i=0; i<checkboxes.length; i++){
    checkboxes[i].checked = this.checked;
    }
    }, false);


    And for the display of the checked items, in HTML:



    <input type="Button" value="Show values" onClick="displayChecked()"/>
    <div id="display"></div>


    Then, in javascript:



    function displayChecked (){
    var display = "";
    checkboxes = document.getElementsByName("viju");
    for( var i=0; i<checkboxes.length; i++){
    if( checkboxes[i].checked ){
    display += " " + checkboxes[i].value;
    }
    }
    document.getElementById("display").innerHTML = display;
    }





    share|improve this answer

































      0














      you could use jquery functions
      dont forget to inclde jquery library



      <button id="showall"> display </button>
      `

      $("#showall").click(function() {



               var array = ;
      $(':checkbox:checked').each(function(i){
      array[i] = $(this).val();
      });

      $.each( array, function( i, val ) {
      $("#display").append(val); //the div where you want to display
      });

      });


      `






      share|improve this answer































        0














        <!DOCTYPE html>
        <html>
        <script>
        var checked=false;
        function checkedAll()
        {
        var c = document.getElementsByName("viju");
        var checkboxesChecked = ;
        // loop over them all
        for (var i=0; i<c.length; i++) {
        // And stick the checked ones onto an array...
        if (c[i].checked) {
        checkboxesChecked.push(c[i]);
        }
        }

        if(document.getElementById('causelist_month').checked)
        {
        checked = document.getElementById('causelist_month');
        checkboxesChecked.push(checked);
        }

        for (var j=0; j<checkboxesChecked.length; j++) {
        // iterate the pushed values
        alert(checkboxesChecked[j].value);
        }

        }
        </script>
        <body>
        <form>
        <input type="checkbox" name="causelist_month" id="causelist_month" value="select all/unselect all" onclick="checkedAll ();">select all/unselect all
        <input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
        <input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
        <input type="Button" value="Show values" onClick="checkedAll(this.value)"/>
        <form>
        </body>
        </html>


        This displays all the list of check boxes in the alert message one by one. please check






        share|improve this answer

























          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22292649%2fdisplay-value-of-checked-check-boxes-javascript%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Jsfiddle http://jsfiddle.net/2UFdc/



          HTML



          <form>
          <input type="checkbox" name="causelist_month" id="causelist_month" onclick="checkedAll ();">select all/unselect all
          <input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
          <input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
          <input type="Button" value="Show values" onClick="showVal(this.form)"/>
          </form>


          Javascript



          var checked = false;

          function checkedAll() {
          var c = document.getElementsByName("viju");
          checked = document.getElementById('causelist_month').checked;

          for (var i = 0; i < c.length; i++) {
          c[i].checked = checked;
          }
          }

          function showVal(frm) {
          var arr = ;
          for (var i in frm.viju) {
          if (frm.viju[i].checked) {
          arr.push(frm.viju[i].value);
          }
          }
          alert(arr);
          return arr
          }





          share|improve this answer




























            0














            Jsfiddle http://jsfiddle.net/2UFdc/



            HTML



            <form>
            <input type="checkbox" name="causelist_month" id="causelist_month" onclick="checkedAll ();">select all/unselect all
            <input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
            <input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
            <input type="Button" value="Show values" onClick="showVal(this.form)"/>
            </form>


            Javascript



            var checked = false;

            function checkedAll() {
            var c = document.getElementsByName("viju");
            checked = document.getElementById('causelist_month').checked;

            for (var i = 0; i < c.length; i++) {
            c[i].checked = checked;
            }
            }

            function showVal(frm) {
            var arr = ;
            for (var i in frm.viju) {
            if (frm.viju[i].checked) {
            arr.push(frm.viju[i].value);
            }
            }
            alert(arr);
            return arr
            }





            share|improve this answer


























              0












              0








              0







              Jsfiddle http://jsfiddle.net/2UFdc/



              HTML



              <form>
              <input type="checkbox" name="causelist_month" id="causelist_month" onclick="checkedAll ();">select all/unselect all
              <input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
              <input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
              <input type="Button" value="Show values" onClick="showVal(this.form)"/>
              </form>


              Javascript



              var checked = false;

              function checkedAll() {
              var c = document.getElementsByName("viju");
              checked = document.getElementById('causelist_month').checked;

              for (var i = 0; i < c.length; i++) {
              c[i].checked = checked;
              }
              }

              function showVal(frm) {
              var arr = ;
              for (var i in frm.viju) {
              if (frm.viju[i].checked) {
              arr.push(frm.viju[i].value);
              }
              }
              alert(arr);
              return arr
              }





              share|improve this answer













              Jsfiddle http://jsfiddle.net/2UFdc/



              HTML



              <form>
              <input type="checkbox" name="causelist_month" id="causelist_month" onclick="checkedAll ();">select all/unselect all
              <input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
              <input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
              <input type="Button" value="Show values" onClick="showVal(this.form)"/>
              </form>


              Javascript



              var checked = false;

              function checkedAll() {
              var c = document.getElementsByName("viju");
              checked = document.getElementById('causelist_month').checked;

              for (var i = 0; i < c.length; i++) {
              c[i].checked = checked;
              }
              }

              function showVal(frm) {
              var arr = ;
              for (var i in frm.viju) {
              if (frm.viju[i].checked) {
              arr.push(frm.viju[i].value);
              }
              }
              alert(arr);
              return arr
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 10 '14 at 5:51









              SajithNairSajithNair

              3,65311321




              3,65311321

























                  0














                  First, use the event listener for the checkboxes rather than onClick:



                  document.getElementById("causelist_month").addEventListener('change', function(){
                  checkboxes = document.getElementsByName("viju");
                  for( var i=0; i<checkboxes.length; i++){
                  checkboxes[i].checked = this.checked;
                  }
                  }, false);


                  And for the display of the checked items, in HTML:



                  <input type="Button" value="Show values" onClick="displayChecked()"/>
                  <div id="display"></div>


                  Then, in javascript:



                  function displayChecked (){
                  var display = "";
                  checkboxes = document.getElementsByName("viju");
                  for( var i=0; i<checkboxes.length; i++){
                  if( checkboxes[i].checked ){
                  display += " " + checkboxes[i].value;
                  }
                  }
                  document.getElementById("display").innerHTML = display;
                  }





                  share|improve this answer






























                    0














                    First, use the event listener for the checkboxes rather than onClick:



                    document.getElementById("causelist_month").addEventListener('change', function(){
                    checkboxes = document.getElementsByName("viju");
                    for( var i=0; i<checkboxes.length; i++){
                    checkboxes[i].checked = this.checked;
                    }
                    }, false);


                    And for the display of the checked items, in HTML:



                    <input type="Button" value="Show values" onClick="displayChecked()"/>
                    <div id="display"></div>


                    Then, in javascript:



                    function displayChecked (){
                    var display = "";
                    checkboxes = document.getElementsByName("viju");
                    for( var i=0; i<checkboxes.length; i++){
                    if( checkboxes[i].checked ){
                    display += " " + checkboxes[i].value;
                    }
                    }
                    document.getElementById("display").innerHTML = display;
                    }





                    share|improve this answer




























                      0












                      0








                      0







                      First, use the event listener for the checkboxes rather than onClick:



                      document.getElementById("causelist_month").addEventListener('change', function(){
                      checkboxes = document.getElementsByName("viju");
                      for( var i=0; i<checkboxes.length; i++){
                      checkboxes[i].checked = this.checked;
                      }
                      }, false);


                      And for the display of the checked items, in HTML:



                      <input type="Button" value="Show values" onClick="displayChecked()"/>
                      <div id="display"></div>


                      Then, in javascript:



                      function displayChecked (){
                      var display = "";
                      checkboxes = document.getElementsByName("viju");
                      for( var i=0; i<checkboxes.length; i++){
                      if( checkboxes[i].checked ){
                      display += " " + checkboxes[i].value;
                      }
                      }
                      document.getElementById("display").innerHTML = display;
                      }





                      share|improve this answer















                      First, use the event listener for the checkboxes rather than onClick:



                      document.getElementById("causelist_month").addEventListener('change', function(){
                      checkboxes = document.getElementsByName("viju");
                      for( var i=0; i<checkboxes.length; i++){
                      checkboxes[i].checked = this.checked;
                      }
                      }, false);


                      And for the display of the checked items, in HTML:



                      <input type="Button" value="Show values" onClick="displayChecked()"/>
                      <div id="display"></div>


                      Then, in javascript:



                      function displayChecked (){
                      var display = "";
                      checkboxes = document.getElementsByName("viju");
                      for( var i=0; i<checkboxes.length; i++){
                      if( checkboxes[i].checked ){
                      display += " " + checkboxes[i].value;
                      }
                      }
                      document.getElementById("display").innerHTML = display;
                      }






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 10 '14 at 5:56

























                      answered Mar 10 '14 at 5:49









                      KyoKyo

                      934510




                      934510























                          0














                          you could use jquery functions
                          dont forget to inclde jquery library



                          <button id="showall"> display </button>
                          `

                          $("#showall").click(function() {



                                   var array = ;
                          $(':checkbox:checked').each(function(i){
                          array[i] = $(this).val();
                          });

                          $.each( array, function( i, val ) {
                          $("#display").append(val); //the div where you want to display
                          });

                          });


                          `






                          share|improve this answer




























                            0














                            you could use jquery functions
                            dont forget to inclde jquery library



                            <button id="showall"> display </button>
                            `

                            $("#showall").click(function() {



                                     var array = ;
                            $(':checkbox:checked').each(function(i){
                            array[i] = $(this).val();
                            });

                            $.each( array, function( i, val ) {
                            $("#display").append(val); //the div where you want to display
                            });

                            });


                            `






                            share|improve this answer


























                              0












                              0








                              0







                              you could use jquery functions
                              dont forget to inclde jquery library



                              <button id="showall"> display </button>
                              `

                              $("#showall").click(function() {



                                       var array = ;
                              $(':checkbox:checked').each(function(i){
                              array[i] = $(this).val();
                              });

                              $.each( array, function( i, val ) {
                              $("#display").append(val); //the div where you want to display
                              });

                              });


                              `






                              share|improve this answer













                              you could use jquery functions
                              dont forget to inclde jquery library



                              <button id="showall"> display </button>
                              `

                              $("#showall").click(function() {



                                       var array = ;
                              $(':checkbox:checked').each(function(i){
                              array[i] = $(this).val();
                              });

                              $.each( array, function( i, val ) {
                              $("#display").append(val); //the div where you want to display
                              });

                              });


                              `







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 10 '14 at 6:05









                              reidreid

                              65110




                              65110























                                  0














                                  <!DOCTYPE html>
                                  <html>
                                  <script>
                                  var checked=false;
                                  function checkedAll()
                                  {
                                  var c = document.getElementsByName("viju");
                                  var checkboxesChecked = ;
                                  // loop over them all
                                  for (var i=0; i<c.length; i++) {
                                  // And stick the checked ones onto an array...
                                  if (c[i].checked) {
                                  checkboxesChecked.push(c[i]);
                                  }
                                  }

                                  if(document.getElementById('causelist_month').checked)
                                  {
                                  checked = document.getElementById('causelist_month');
                                  checkboxesChecked.push(checked);
                                  }

                                  for (var j=0; j<checkboxesChecked.length; j++) {
                                  // iterate the pushed values
                                  alert(checkboxesChecked[j].value);
                                  }

                                  }
                                  </script>
                                  <body>
                                  <form>
                                  <input type="checkbox" name="causelist_month" id="causelist_month" value="select all/unselect all" onclick="checkedAll ();">select all/unselect all
                                  <input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
                                  <input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
                                  <input type="Button" value="Show values" onClick="checkedAll(this.value)"/>
                                  <form>
                                  </body>
                                  </html>


                                  This displays all the list of check boxes in the alert message one by one. please check






                                  share|improve this answer






























                                    0














                                    <!DOCTYPE html>
                                    <html>
                                    <script>
                                    var checked=false;
                                    function checkedAll()
                                    {
                                    var c = document.getElementsByName("viju");
                                    var checkboxesChecked = ;
                                    // loop over them all
                                    for (var i=0; i<c.length; i++) {
                                    // And stick the checked ones onto an array...
                                    if (c[i].checked) {
                                    checkboxesChecked.push(c[i]);
                                    }
                                    }

                                    if(document.getElementById('causelist_month').checked)
                                    {
                                    checked = document.getElementById('causelist_month');
                                    checkboxesChecked.push(checked);
                                    }

                                    for (var j=0; j<checkboxesChecked.length; j++) {
                                    // iterate the pushed values
                                    alert(checkboxesChecked[j].value);
                                    }

                                    }
                                    </script>
                                    <body>
                                    <form>
                                    <input type="checkbox" name="causelist_month" id="causelist_month" value="select all/unselect all" onclick="checkedAll ();">select all/unselect all
                                    <input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
                                    <input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
                                    <input type="Button" value="Show values" onClick="checkedAll(this.value)"/>
                                    <form>
                                    </body>
                                    </html>


                                    This displays all the list of check boxes in the alert message one by one. please check






                                    share|improve this answer




























                                      0












                                      0








                                      0







                                      <!DOCTYPE html>
                                      <html>
                                      <script>
                                      var checked=false;
                                      function checkedAll()
                                      {
                                      var c = document.getElementsByName("viju");
                                      var checkboxesChecked = ;
                                      // loop over them all
                                      for (var i=0; i<c.length; i++) {
                                      // And stick the checked ones onto an array...
                                      if (c[i].checked) {
                                      checkboxesChecked.push(c[i]);
                                      }
                                      }

                                      if(document.getElementById('causelist_month').checked)
                                      {
                                      checked = document.getElementById('causelist_month');
                                      checkboxesChecked.push(checked);
                                      }

                                      for (var j=0; j<checkboxesChecked.length; j++) {
                                      // iterate the pushed values
                                      alert(checkboxesChecked[j].value);
                                      }

                                      }
                                      </script>
                                      <body>
                                      <form>
                                      <input type="checkbox" name="causelist_month" id="causelist_month" value="select all/unselect all" onclick="checkedAll ();">select all/unselect all
                                      <input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
                                      <input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
                                      <input type="Button" value="Show values" onClick="checkedAll(this.value)"/>
                                      <form>
                                      </body>
                                      </html>


                                      This displays all the list of check boxes in the alert message one by one. please check






                                      share|improve this answer















                                      <!DOCTYPE html>
                                      <html>
                                      <script>
                                      var checked=false;
                                      function checkedAll()
                                      {
                                      var c = document.getElementsByName("viju");
                                      var checkboxesChecked = ;
                                      // loop over them all
                                      for (var i=0; i<c.length; i++) {
                                      // And stick the checked ones onto an array...
                                      if (c[i].checked) {
                                      checkboxesChecked.push(c[i]);
                                      }
                                      }

                                      if(document.getElementById('causelist_month').checked)
                                      {
                                      checked = document.getElementById('causelist_month');
                                      checkboxesChecked.push(checked);
                                      }

                                      for (var j=0; j<checkboxesChecked.length; j++) {
                                      // iterate the pushed values
                                      alert(checkboxesChecked[j].value);
                                      }

                                      }
                                      </script>
                                      <body>
                                      <form>
                                      <input type="checkbox" name="causelist_month" id="causelist_month" value="select all/unselect all" onclick="checkedAll ();">select all/unselect all
                                      <input type="checkbox" name="viju" id="viju" value="Jan" onClick="">jan
                                      <input type="checkbox" name="viju" id ="viju" value="feb" onClick="">feb
                                      <input type="Button" value="Show values" onClick="checkedAll(this.value)"/>
                                      <form>
                                      </body>
                                      </html>


                                      This displays all the list of check boxes in the alert message one by one. please check







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Mar 10 '14 at 6:24

























                                      answered Mar 10 '14 at 6:13









                                      SriSaiKiranSriSaiKiran

                                      335




                                      335






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22292649%2fdisplay-value-of-checked-check-boxes-javascript%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Florida Star v. B. J. F.

                                          Danny Elfman

                                          Lugert, Oklahoma