Próbuję pobrać tekst z pola tekstowego.Uzyskiwanie wartości wejściowych z pola tekstowego
Mam 2 pola tekstowe wejściowe, które nie są w formie, i próbuję pobrać value
i zapisać go w zmiennej. Ten kod zwraca undefined
w wyświetlonym oknie alertu.
<script>
var userPass = document.getElementById('pass');
var userName = document.getElementById('fName');
function submit(){
alert(userPass.value);
}
</script>
Kiedy uruchamiam go z userName.value
jako parametr w funkcji ostrzegania, to będzie działać i wyświetlać cokolwiek wpiszesz w polu.
Oto 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>
– Beanno1116
Jakie jest twoje pytanie? – blake305
dodaj odpowiedni html –