How to assign a number to a button or class, for example, 100, click on the button where the number 100 is assigned and then click on another button and this number 100 is assigned to another button, who can offer or correct me

Closed due to the fact that off-topic participants are enzo , Grundy , cheops , zRrr , Streletz 21 Jun '16 at 9:24 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - zRrr, Streletz
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • I propose to correct the question - Mr. Black

1 answer 1

I think, based on a complex issue, it looks like this.

We press the first button, we get 100
We press the second and assign the value of the first

first = document.querySelector('#first'); second = document.querySelector('#second'); get = 0; first.onclick = function() { get = this.value; } second.onclick = function() { this.value = get; } 
 <input id='first' type='button' value='100'> <input id='second' type='button' value='0'> 

  • And if there are a lot of buttons in the html code, how to choose the right one? - Timur3250
  • @ Timur3250, specify a brute force input class for each or your own original id - Mr. Black
  • @ Timur3250, updated the example with id - Mr. Black
  • I see, I understand you. - Timur3250
  • The code that you wrote and just need to insert a document into js? - Timur3250