lundi 25 janvier 2016

recover all values of checked checkboxes and push them in an array

I am usiing twig in my php project.

I have a form which contains many checkboxes. I need, in javascript to recover all checked values of the checkbox in an array.

This is the javascript:

<script type="text/javascript" charset="utf-8" async defer>
  document.getElementById("{{ value }}").onclick = function() { /* {{ value }} is value of my checkboxe, twig variable it matches like a php variable */
    if ( this.checked ) { /* check if checkboxes are checked */
      var valueChecked = this.value;
      console.log(valueChecked); /* just to display the value for debug */

      var valueArray = []; /* I create an array */
      /* here I need to put all my checkboxes values in allCheckedConfig */
    } else {
      console.log("removed " + this.value ); /* just to debug, check if checkboxes are unchecked */
    }
  };
</script>

How can I populate my valueArray[] ?




Aucun commentaire:

Enregistrer un commentaire