Setting a variable with a link

Good day to all.

<input name="text_01" type="text" value="" readonly="true">
<a name="123" onClick="document.getElementById('text_01').value = '123';">123</a>

In one of my threads, I asked a question about an alternative to onclick actions. We press the link, and in the textbox the value I need. The design above appears to work on 3.5 out of 10 computers, not including the IE browser (everything is in it). I don’t want to start meaningless conversations for some reason.

I’m wondering if it’s possible to somehow set a value for a certain variable when clicking on a link, and in “text_01” to update every second? Or any alternative, as long as it works.

Answer 1, authority 100%

In your code, you say document.getElementById(‘text_01’), meaning you want to get the element with ID(!!) = text_01. as you noticed in your code there is no such element with that ID. Therefore, you need to use another function: document.getElementByName(‘text_01’) or add an ID attribute to the text_01


Answer 2, authority 25%

try with jQuery

<input name="text_01" id="text_01" type="text" value="" readonly="true">
<a name="123" onClick="$('#text_01').val('123');">123</a>