Smartmonkey
11-12-2004, 09:25 PM
Ok I think my issue here is that this is a local variable and not a global variable, but I am trying to take this code and make it so it will count text in multiple text fields, instead of one:
<html>
<head>
<title>New Page 1</title>
<script language = "Javascript">
function taLimit() {
var taObj=event.srcElement;
if (taObj.value.length==taObj.maxLength*1) return false;
}
function taCount(visCnt) {
var taObj=event.srcElement;
if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
</script>
</head>
<body>
<label for="ITCon">IT Contact Info: </label>
<input type="text" name="ITCon" title="IT Contact Info: " onkeypress="return taLimit()" onkeyup="return taCount(myCounter)" maxLength="348" >
<Label for="description">Problem Description: </label>
<TEXTAREA onkeypress="return taLimit()" onkeyup="return taCount(myCounter)"
name=Description wrap=physical rows=4 cols=40 maxLength="348"></TEXTAREA>
<br><br>
You have <B><SPAN id=myCounter>348</SPAN></B> characters remaining
for your description...
</body>
</html>
If you see here the problem is, it will count text from each field seperately.
I don't know if I was going about this right or not but I was going to try and declare the variable at the beginning of the code by changing it to this:
<script language = "Javascript">
var taObj=event.srcElement;
function taLimit() {
if (taObj.value.length==taObj.maxLength*1) return false;
}
function taCount(visCnt) {
if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
</script>
but of course when I run that I get an error saying taObj is null or not an object.
Sorry if I am way off base here, but im a newb.. just trying to piece my way through this. If there is a better way to count all the text im all ears.. but I really do appreciate any help that can be offered =)
<html>
<head>
<title>New Page 1</title>
<script language = "Javascript">
function taLimit() {
var taObj=event.srcElement;
if (taObj.value.length==taObj.maxLength*1) return false;
}
function taCount(visCnt) {
var taObj=event.srcElement;
if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
</script>
</head>
<body>
<label for="ITCon">IT Contact Info: </label>
<input type="text" name="ITCon" title="IT Contact Info: " onkeypress="return taLimit()" onkeyup="return taCount(myCounter)" maxLength="348" >
<Label for="description">Problem Description: </label>
<TEXTAREA onkeypress="return taLimit()" onkeyup="return taCount(myCounter)"
name=Description wrap=physical rows=4 cols=40 maxLength="348"></TEXTAREA>
<br><br>
You have <B><SPAN id=myCounter>348</SPAN></B> characters remaining
for your description...
</body>
</html>
If you see here the problem is, it will count text from each field seperately.
I don't know if I was going about this right or not but I was going to try and declare the variable at the beginning of the code by changing it to this:
<script language = "Javascript">
var taObj=event.srcElement;
function taLimit() {
if (taObj.value.length==taObj.maxLength*1) return false;
}
function taCount(visCnt) {
if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
</script>
but of course when I run that I get an error saying taObj is null or not an object.
Sorry if I am way off base here, but im a newb.. just trying to piece my way through this. If there is a better way to count all the text im all ears.. but I really do appreciate any help that can be offered =)