190
rated 0 times
[
193]
[
3]
/ answers: 1 / hits: 189261
/ 13 Years ago, mon, january 16, 2012, 12:00:00
I'm trying to get the text from a text box.
I have 2 input text boxes that are not in a form, and I'm trying to retrieve the value
and store it in a variable.
This code returns undefined
in the alert box that pops up.
<script>
var userPass = document.getElementById('pass');
var userName = document.getElementById('fName');
function submit(){
alert(userPass.value);
}
</script>
When I run it with userName.value
as a parameter in the alert function, it will work and display what ever you type in the box.
Here is the html:
<table id=login>
<tr>
<td><label>User Name</label></td>
</tr>
<tr>
<td colspan=2><input class=textBox id=fName type=text maxlength=30 required/></td>
</tr>
<tr>
<td id=pass><label>Password</label></td>
<tr>
<td colspan=2><input class=textBox id=pass type=text maxlength=30 required/></td>
</tr>
<tr>
<td><input type=button class=loginButtons value=Login onclick=submit();/>   
<input type=button class=loginButtons value=Cancel/></td>
</table>
More From » html