Gossamer Forum
Home : General : Internet Technologies :

Javascript: Obtain value length

Quote Reply
Javascript: Obtain value length
I know I am missing something very simplistic here, but I just can't figure it out.

I have a password field:

<INPUT TYPE="password" ID="password" NAME="password" VALUE="">

I also have a hidden field to hold the length of the password:

<INPUT TYPE="text" ID="password_length" NAME="password_length" VALUE="">

The reason I need to find the length of the password is because when the user clicks on the submit button, I convert the password into an MD5 hash before it is sent and I need to know if the password length before it is converted.

I could have a javascript detect the length and give an alert if it is under x characters, but since other error messages are displayed after the submission, I'd rather keep all error messages together.

To detect the length, here is what I was doing:

<INPUT TYPE="submit" NAME="submit" VALUE="Submit" onclick = "password_length.value = password.length">

When I submit and look at the tag (I use a value of $_POST[password_length]), the value is "undefined". What am I doing wrong?
Quote Reply
Re: [Lee] Javascript: Obtain value length In reply to
What about password.value.length?
Quote Reply
Re: [Lee] Javascript: Obtain value length In reply to
Check out:

http://javascript.internet.com

and look under "forms" - they've got a bunch of cut-n-paste types of code snippets. I know there is something in there about limiting number of characters that you can hack/adapt for your purposes.
Quote Reply
Re: [TypeR] Javascript: Obtain value length In reply to
Thanks TypeR!!! That did the trick. I knew it had to be something little I was overlooking.

Again, thanks.