I have two buttons and a text field. I want to update the display of the text field with the value of the buttons each time a button is pressed.
function displayTextfield() {
var amount;
amount = document.getElementById('btn').value;
document.getElementById('other-amount') = amount;
}
<button class="btn btn-default" id="btn" onclick='displayTextfield()' role="button" value="A">A</button>
<button class="btn btn-default" id="btn" onclick='displayTextfield()' role="button" value="B">B</button>
<input type="text" class="form-control donation-amount-input" placeholder="Other Amount" id="other-amount" onclick='displayTextfield()'/>
When I run the click the button I get the error:
Uncaught TypeError: Cannot read property 'value' of null
#valueanywhere in your HTML.