Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

text field input counter mod 1

Status
Not open for further replies.

Dashley

Programmer
Joined
Dec 5, 2002
Messages
925
Location
US
I have this JS code in a classic ASP page. I can see where and how it applies to all text areas ("src_element.type == 'textarea'" )

I also want to have it count the characters in a textbox named "cpd19"
example: <input name="cdp19" size="6" tabindex="19">

My knowlege of JS is very limited.

Can the if statment be modified or another added to include an input field named cpd19

Thanks



Code:
function MaxLengthChecker(e)	{
	// max length field checker
	var max_text_length = 3950;
	// where am i?
	// get object i am in
	// if the object is a text area then execute textcounter()
	var counted_chars = 0;
	var src_element = e.srcElement? e.srcElement : e.target;
	if (src_element != null)	{
		if (src_element.value.length > max_text_length) {
			src_element.value = src_element.value.substring(0, max_text_length);
			window.alert('Maximum Character Length Reached.');					
			counted_chars = max_text_length;
			}
		else 
			counted_chars = max_text_length - src_element.value.length;
		if (src_element.type == 'textarea')		{
			popup(counted_chars + ' Characters Left');
		}
		return true;
	}	else	{
		return false;
	}					
}
 
If you want to include generally text input, it is this.
[tt] if (src_element.type == 'textarea' || src_element.type == 'text') {[/tt]
If you mean specifically to include a know input element named cdp19 be it a text type or something else, it is this.
[tt] if (src_element.type == 'textarea' || src_element.namee == 'cdp19') {[/tt]
 
tsuji


Thanks. Actually the second one is what I need but I'm sure I'll use both along the way.
Thanks again I appreciate it


Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top