How to set the value property of the input element, the value of the id of the button used to click?

There are 4 buttons with the class btn and each key has its own id, there is also a separate form to submit a request with the element input has its own id="wtch_name".
You need to by clicking on any of the 4 buttons in the the value value of this input were substituted the id of the pressed button.

Here is my code below but it does not work what is wrong?

$('.btn').click(function() {
$('#wtch_name').value = $(this).attr('id'));
March 23rd 20 at 18:45
2 answers
March 23rd 20 at 18:47
Thank you, but in my version there is an error or completely wrong doing? - Gregorio commented on March 23rd 20 at 18:50
@Gregorio, Yes of course wrong - you tried to assign the value not the element and collection elements. It is necessary to use a method of collection of val (as in the answer above), or to a separate element: $('#wtch_name')[0].value =;. - audreanne45 commented on March 23rd 20 at 18:53
@audreanne45, Hey, still such question and how to implement then another was substituted element of a certain class depending on the id? - Gregorio commented on March 23rd 20 at 18:56
@Gregorio, between the original question and that your "still such question" it's been 35 days. I would and after 5 hardly remembered what it was. Make a new question where it will be explained in detail that is causing you difficulties. - audreanne45 commented on March 23rd 20 at 18:59
March 23rd 20 at 18:49
but it's not working what's the error?

How do we know you're not layout, nor is there anything in the console said.

Replied yesterday to a similar question, but with Cheboksari instead of buttons.
How to make the selected amount appeared in the text?

Find more questions by tags jQuery