I am new to Javascript and learning to build a calculator as my first project. I don't understand why I am unable to get the value from the display to pass through the function via DOM. I've looked at other examples with a similar implementation, but don't understand why mine does not work. Can someone help explain this to me?
HTML:
<form class="output-wrapper" name="output-wrapper"> <input type="text" name="display" disabled> <div class="calc-btn-wrapper"> <div class="nmb-btn container"> <button type="button" value="1" onclick="calcfunc(1)">1</button> <button type="button" value="2" onclick="calcfunc(2)">2</button> <!-- ... --> <!-- ... --> </form> JavaScript:
function calcfunc (num){ var display = document.form['output-wrapper']['display'].value; if (display ==="" || display===0){ let newvalu = display+num; document.form['output-wrapper']['display'].value=newvalu; };
document.form.getElementById,querySelector,querySlectorAll,getElementsByClassNameetc.