Character count problem..
-
Hey all I've got an aspx page that has a number of text boxes on it. I have the following javascript function that counts characters within the text box: function myLength(lbl,tb,max){ //lbl is the ID of the control that displays the count //tb is the ID of the control that is being counted //max is the maximum amount of characters allowed in the control lbl.innerHTML = tb.innerHTML.length + " of " + max; } Within the vb page associated to the aspx page I have the following code: txtTitle.Attributes.Add("OnKeyUp", "myLength(document.getElementById('" _ + lblWC_Title.ClientID + "'),document.getElementById('" + _ txtTitle.ClientID + "')," + txtTitle.MaxLength.ToString + ")") This adds the onkeyup event to the text box and passes the correct client ID's into the javascript function. Now my problem is this, if my asp text box is multiline then the word count works fine but nothing happens if it is a text box set to be single line. I use the same methods as shown above for both types of text box. Any ideas on what is causing this? Thanks in advance W.:)
-
Hey all I've got an aspx page that has a number of text boxes on it. I have the following javascript function that counts characters within the text box: function myLength(lbl,tb,max){ //lbl is the ID of the control that displays the count //tb is the ID of the control that is being counted //max is the maximum amount of characters allowed in the control lbl.innerHTML = tb.innerHTML.length + " of " + max; } Within the vb page associated to the aspx page I have the following code: txtTitle.Attributes.Add("OnKeyUp", "myLength(document.getElementById('" _ + lblWC_Title.ClientID + "'),document.getElementById('" + _ txtTitle.ClientID + "')," + txtTitle.MaxLength.ToString + ")") This adds the onkeyup event to the text box and passes the correct client ID's into the javascript function. Now my problem is this, if my asp text box is multiline then the word count works fine but nothing happens if it is a text box set to be single line. I use the same methods as shown above for both types of text box. Any ideas on what is causing this? Thanks in advance W.:)
-
Have you examined the code that is created (e.g. view source in browser), to see what is missing?
--- b { font-weight: normal; }
Sorry for taking so long to reply, didnt email me like it said it would. The problem is solved, it was because a textbox with multiline selected is rendered as textarea which has both innerHTML and innerTEXT where as a single line text box does not have either of these. Instead changing the .innerHTML or .innerTEXT to simply '.value' solved the problem. Thanks for replying.