lundi 18 mai 2020

How do get the value of only checked checkboxes in Javascript?

This is my first post here. I am having an issue with my form. I want to be able to get the values of ONLY the boxes that are checked on the form and have them be added to one of the inputs. The issue is I am either getting all of the checkboxes (checked or not) or I am getting undefined. The checkboxes are like this

<input type="checkbox" className="checkbox" value="Triatholons" />
              Triathlon Training Plans
            </label>
    ```
    //and the function I have been trying is this 
    function itworked() {
  alert("Sky will contact you shortly!")
  var values = document.getElementsByClassName("checkbox:checked")
  console.log(values)
  }

This is returning an HTML collection, when I try and extract the value I only get undefined. What am I missing here? Thank you for your help.




Aucun commentaire:

Enregistrer un commentaire