Grab Value from multiple buttons in Javascript

Asked

Viewed 329 times

-1

How to get the value of various buttons using Javascript ?

Qual cor você prefere ?
_______ ______ ______
|verde| |Azul| |Rosa|
------- ------ ------

Qual sorvete você prefere ?
___________ _________ ______
|Chocolate| |Morango| |Uva|
----------- --------- ------

And if the person selects "Blue" and "Chocolate" for example this value is displayed in a div.

2 answers

-1

In that case, you’d better use input type="radio" in your HTML and take the value of these inputs with Javascript to insert dps into a div.

  • and that I’m trying to do the same logic of the buttons of Buzzfeed for example, which are buttons for what I understand, but I’m not sure if this is possible

  • Then you could put functions in the "onclick" property of the buttons where by clicking one of them you put the "disabled" property of the other two as "true"

-1

<select id="mySelect">
  <option>Verde</option>
  <option>Azul</option>
  <option>Rosa</option>
</select>


<button onclick="myFunction()">Click</button>

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

<script>
function myFunction() {
  var x = document.getElementById("mySelect").value;
  document.getElementById("demo").innerHTML = x;
}
</script>
  • In this case it leaves the pattern that I am trying to do, in case I wanted something similar to the logic of the buttons of Buzzfeed

Browser other questions tagged

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