2

Trying to press a button which outputs text in an input field. the function is to output text "x" into input field upon press, which is set to read only. only js and html allowed. Here's what i got so far in HTML and js:

 <button id="button4" onclick="output()">Hokus Pokus</button>
 <input id="printoutput" readonly="true" type="text">

js:

function output() {

document.getElementById("printoutput").innerHTML = "x";

}

Why does this not work?

1
  • Oh my, that was a very obvious oversight on my part. Thanks! Commented Oct 16, 2018 at 16:30

3 Answers 3

2

Do it like this and it works like a charm:

function output() {

document.getElementById("printoutput").value = "x";

}
 <button id="button4" onclick="output()">Hokus Pokus</button>
<input id="printoutput" readonly="true" type="text">

Sign up to request clarification or add additional context in comments.

Comments

1

Fixed. did this:

function output() {

document.getElementById("printoutput").innerHTML = "x";

}

When it should be:

function output() {

document.getElementById("printoutput").value = "x";

}

Comments

0

You need to set the value of the input, not the inner html

document.getElementById("printoutput").value = "x";
<button id="button4" onclick="output()">Hokus Pokus</button>
 <input id="printoutput" readonly="true" type="text">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.