Breadit Breadit - 1 year ago 51
HTML Question

Changing Input Text Value JS

Breadit here and I have a problem. I tried to look everywhere but can't find a single answer that will work. I am trying to make a button which will square the first tag and will print the output on the second tag.


function square() {
var a=document.getElementById("inputSquare");
var b=a*a;


<input type="number" id="inputSquare">
<button onclick="square()">=</button>
<input type="number" id="outputSquare" readonly>

That is my problem.

Answer Source

Hey Breadit with a problem. Try this:

function squaree() {
    var a=document.getElementById("inputSquare").value;
    var b=a*a;

Also. you have to put the code in <script> tag inside head. Not in dom load or jquery ready function. Check it out here: