How does every click on the checkbox count for a number?

Asked

Viewed 96 times

-2

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

inserir a descrição da imagem aqui

  • Looking at the image and taking it as an example, I assume that you want to associate a number with each checkbox so that when you press Compare, the program knows what to compare with the clicked checkboxes. Correct?

  • your checkbox looks like this: Checkbox: <input type="checkbox" id="myCheck" value="myvalue">. assigns a value for each value

  • It’s not that the checkbox side had an input number and I took it out, and I wanted every click I give in the checkbox to be equivalent to a number in the input number @Israelzebulon

  • takes this answer code and implements it within myFunction()

  • @Israelzebulon put it didn’t work

  • add an input to the side and give an id to it.... within the function you use Document.getElementById(id). value; to add or take the value inside the input

Show 1 more comment

1 answer

2

A very simplistic solution would be 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.