How to make each click on the checkbox worth a number? [closed]

-2

I would like to know how I can do for each click that I am worth one by a number, type instead of I put an input number next to the checkbox I would like to make every click I give in checkebox worth by a number .

    
asked by anonymous 29.01.2017 / 02:17

1 answer

2

A very simplistic solution would look something like this:

<!DOCTYPE html>
<html>
<body>

Checkbox: <input type="checkbox" id="m1" value="1" onclick="myFunction('m1')">

Checkbox: <input type="checkbox" id="m2" value="2" onclick="myFunction('m2')">

Checkbox: <input type="checkbox" id="m3" value="3" onclick="myFunction('m3')">

<p>Click the "Try it" button to display the value of the value attribute of the checkbox.</p>
 
<p id="demo"></p>

<script>
function myFunction(id) {
    var x = document.getElementById(id).value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>
    
29.01.2017 / 02:36