Previously, I had this line in my HTML file:
<input type="button" value="1" name="btn1" id="btn1" onclick="showNum(1)" />
This works fine, but I don't want to include the method name in the HTML file. I would like to have something like this in the HTML:
<input type="button" value="1" name="btn1" id="btn1" />
And then I want to bind this button to the method in the JS file. I tried this code and it doesn't work:
window.onload = function() {
document.getElementById("btn1").onclick = showNum(1);
};
How can I bind btn1 to run showNum(1) using JavaScript?
showNumalways the same as thevalueof the input?