dimanche 11 février 2018

How to use JQuery to get the value property of a checkbox in a form?

I want to use either Javascript or JQuery to get the value of a checkbox when it is checked.

How can I do that? Please see question marks in the JQuery code below.

<html>
<body>

<form id="toggleForm" action="">
<input type="checkbox" name="vehicle" value="Bike">I have a bike<br>
<input type="checkbox" name="vehicle" value="Car">I have a car 
</form>

<script>
$('???').on('checked???', function(){
   var checkedValue = $(this).attr('value???');
   console.log("The checkbox value property is "+checkedValue);
});
</script>

</body>
</html>




Aucun commentaire:

Enregistrer un commentaire