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
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;
}
}