mike55 Posted December 20, 2005 Posted December 20, 2005 (edited) Hi all, A standard web page has a opening and closing head, body, and form tag. I have a some javascript, that calculates the number of characters that each user left, given that the user cannot enter more that 254 characters. The problem that I am new experiencing is that the java script has to reference the id property of the Form tags. Unfortunately no such tags, (from my previous attempts) exists in user controls. I was using the id property to access other controls on the web page, using the following code: 'document.' + FormName + '.' + TextFieldName + '.value'; Is their any possible means of repeating this functionality using the web control. I cannot set the textbox control properties "MaxLength" as the textbo is a multi-line text area. Here is the entire javascript: var MaximumCharacters = "254"; var MaximumWords = "0"; var FormName = "usrctrlHistory1"; var TextFieldName = "txtComment"; var CharactersTypedFieldName = ""; var CharactersLeftFieldName = "CharsLeft"; var WordsTypedFieldName = ""; var WordsLeftFieldName = ""; var WordsMonitor = 0; var MaxWords = parseInt(MaximumWords); var MaxChars = parseInt(MaximumCharacters); var textfield = 'document.' + FormName + '.' + TextFieldName + '.value'; function WordLengthCheck(s,l) { WordsMonitor = 0; var f = false; var ts = new String(); for(var vi = 0; vi < s.length; vi++) { vs = s.substr(vi,1); if((vs >= 'A' && vs <= 'Z') || (vs >= 'a' && vs <= 'z') || (vs >= '0' && vs <= '9')) { if(f == false) { f = true; WordsMonitor++; if((l > 0) && (WordsMonitor > l)) { s = s.substring(0,ts.length); vi = s.length; WordsMonitor--; } } } else { f = false; } ts += vs; } return s; } // function WordLengthCheck() function CharLengthCheck(s,l) { if(s.length > l) { s = s.substring(0,l); } return s; } // function CharLengthCheck() function InputCharacterLengthCheck() { if(MaxChars <= 0) { return; } var currentstring = new String(); eval('currentstring = ' + textfield); var currentlength = currentstring.length; eval('currentstring = CharLengthCheck(' + textfield + ',' + MaxChars + ')'); if(CharactersLeftFieldName.length > 0) { var left = 0; eval('left = ' + MaxChars + ' - ' + textfield + '.length'); if(left < 0) { left = 0; } eval('document.' + FormName + '.' + CharactersLeftFieldName + '.value = ' + left); if(currentstring.length < currentlength) { eval(textfield + ' = currentstring.substring(0)'); } } if(CharactersTypedFieldName.length > 0) { eval('document.' + FormName + '.' + CharactersTypedFieldName + '.value = ' + textfield + '.length'); if(currentstring.length < currentlength) { eval(textfield + ' = currentstring.substring(0)'); } } } // function InputCharacterLengthCheck() function InputWordLengthCheck() { if(MaxWords <= 0) { return; } var currentstring = new String(); eval('currentstring = ' + textfield); var currentlength = currentstring.length; eval('currentstring = WordLengthCheck(' + textfield + ',' + MaxWords + ')'); if (WordsLeftFieldName.length > 0) { var left = MaxWords - WordsMonitor; if(left < 0) { left = 0; } eval('document.' + FormName + '.' + WordsLeftFieldName + '.value = ' + left); if(currentstring.length < currentlength) { eval(textfield + ' = currentstring.substring(0)'); } } if (WordsTypedFieldName.length > 0) { eval('document.' + FormName + '.' + WordsTypedFieldName + '.value = ' + WordsMonitor); if(currentstring.length < currentlength) { eval(textfield + ' = currentstring.substring(0)'); } } } // function InputWordLengthCheck() function InputLengthCheck() { InputCharacterLengthCheck(); InputWordLengthCheck(); } // function InputLengthCheck() Mike55. Edited December 20, 2005 by mike55 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Diesel Posted December 20, 2005 Posted December 20, 2005 http://javascript.internet.com/forms/limit-textarea.html Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.