I have an HTML input textbox, and I'm trying to pass the value of it to a JavaScript function. The code for the textbox is as follows;
<input type="text" id="fname">
<input type="button" onclick="success()">
I use this to get the value of the textbox;
var depttxt = document.getElementsByID('fname');
However when I try to find the value of the value like so;
function success() {
alert(depttxt);
}
The alert box says undefined
. If then put .value
after the variable in the alert, it breaks and no alert box shows up. Can anyone tell me what I'm doing wrong here?
Thanks all!