checkbox query

0

Can someone please help me? How do I get a value other than true or false in the checkbox? Example: I click on the "test" checkbox. I do not want the word "test" to appear, not true. Thanks!

    
asked by anonymous 27.07.2015 / 19:40

1 answer

0

You must enter a value for the input checkbox. See the code below

<!DOCTYPE html>
<html>
<body>

Checkbox: <input type="checkbox" id="meucheckbox" value="QualquerValor">
<p>Clique no botão para ver o resultado do checkbox</p>

<button onclick="pegarValor()">Testar</button>

<p id="demo"></p>

<script>
function pegarValor() {
    var x = document.getElementById("meucheckbox").value;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
    
27.07.2015 / 19:49