Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Checking for length of strings in Javascript

I have 6 fields on a page. User clicks OK and I want to check the length of each field in Javascript and then display on the asp.net page which field needs to be longer...

Any examples ?
ASKER CERTIFIED SOLUTION
Avatar of mrichmon
mrichmon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

let me try it. I think I want to check for all 6 fields and then display on the aspx page the ones that dont meet the length critetria. Let me play around with it and post back.
ok, i got the main part done but I have a question. This is what I have:
var txtHPhone = document.getElementById('<%= Page.Master.FindControl("ContentPlaceHolder1").FindControl("txtHPhone").ClientID %>');

....
 else if ( txtHPhone.value.length <= 3)
            {
             document.getElementById('<%= Page.Master.FindControl("ContentPlaceHolder1").FindControl("lblError").ClientID %>').innerHTML = "<b>Length of your search field must be greater than 3</b>";
            }

**** How can I specify the name of the field ? For example : Length of Home Phone field must be greater than 3... ***Note "Home Phone". So how do I get the label name in there?
I tried this but didnt work:
 document.getElementById('<%= Page.Master.FindControl("ContentPlaceHolder1").FindControl("lblHPhone").ClientID %>')