Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
179
rated 0 times [  185] [ 6]  / answers: 1 / hits: 7412  / 11 Years ago, mon, december 2, 2013, 12:00:00

I am trying to read the length of a textbox from my register form. I have tried using document.getElementById() and textbox.value.length. Is there something very simple I'm am missing. I alert the result to the screen to show the textbox length. Thanks in advance.



Here is my last attempt:



function Register(){
Alert(RegisterForm.txt_Password.value.length);
}


TextBox structure:



<form id=RegisterForm name=RegisterForm method=POST action=RegisterInsert.php onsubmit=return Register(RegisterForm)>
<table border=0 align=center width=100%>
<tr>
<td width=15%>Email Address:</td>
<td width=85%><input type=text name=txt_Email id=txt_Email/> </td>
</tr>
<tr>
<td width=15%>Username:</td>
<td width=85%><input type=text autocomplete=off name=user_name id=user_id class=user_name >
<span class=check ></span></td>
</tr>
<tr>
<td width=15%>Password:</td>
<td width=85%><input type=password name=txt_Password id=txt_Password /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type=submit name=btn_Register id=btn_Register value=Register></td>
</tr>
<tr>
</table>
<p>&nbsp;</p>
</form>


I use the submit button to call the Register function.


More From » javascript

 Answers
106

You need to get a reference to the element first:



function Register() {
var RegisterForm = document.getElementById('RegisterForm');
alert(RegisterForm.elements['txt_Password'].value.length);
}

[#49927] Sunday, December 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
karladaijahf

Total Points: 78
Total Questions: 123
Total Answers: 89

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;