<input type="text" id="fname"> <input type="text" id="lname"> <input type="button" value="Enter" id="fsubmit"> You need to get the value fname or lname by calling the getVal function. I tried
function getValue(e){ console.log(e.value); } var fsubmit = document.getElementById("fsubmit"); fsubmit.onclick = getValue("fname"); The console issues undefined immediately upon boot, without clicking. It works only this way (at the input itself):
function getValue(){ console.log("Button clicked, value "+ this.value); } var fname = document.getElementById("fname"); fname.onclick = getValue;