Limit number of characters entered - firefox

Hi everyone,

See http:Q_21477840.html#14349933 for a little background information.
I'm trying to figure out how to get this to work in firefox, I believe IE and mozilla will be the only two browsers used to send me anything.  Neither the maxLength nor the counter work.  The link I was given there is for IE4+, I was hoping it would still work on firefox, but unfortunately not :)

  <form method="post" action="/sent.asp">
   Your Name:<BR>
   <TEXTAREA onkeypress="return taLimit()" onkeyup="return taCount(myCounter1)"
   name=subject rows=1 wrap=physical cols=40 maxLength="13"></TEXTAREA><br>
   You have <B><SPAN id=myCounter1>13</SPAN></B> characters remaining.</font><BR>
   <BR>
   Your Message:<BR>
   <TEXTAREA onkeypress="return taLimit()" onkeyup="return taCount(myCounter2)"
   name=body rows=4 wrap=physical cols=40 maxLength="115"></TEXTAREA><br>
   You have <B><SPAN id=myCounter2>115</SPAN></B> characters remaining.</font><BR>
   <BR>
   <input type="submit" name="submit" value="Send Me A Text Message!">
  </form>

<script language = "Javascript">
/* textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */

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>

If this can be done, I'll increase the points, but I'm leaving it at 125 for a "nope, you're out of luck" answer
Thanks!
Matt
LVL 35
mvidasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Crossroads305Commented:
I believe it may be a problem with that fact that Firefox supports the W3C standard of using getElementById() instead of the innerHTML or innerText that has become an MS standard.   I don't know exactly how to use the getElementById(), but check out the W3C web site or w3schools.com for more information
mvidasAuthor Commented:
I will take a look later and see if I can figure it out, unfortunately I have to leave now and won't be returning to this for a while.  Thanks for the suggestion!
I'll take any more as well, if anyone else can help
Crossroads305Commented:
try this:  (only updates the body, u can create a similar function to update the subject)

<script language = "Javascript">
/* textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */

function taLimit() {
     var taObj=event.srcElement;
     if (taObj.value.length==taObj.maxLength*1) return false;
}

function taCount(visCnt) {
      document.getElementById("myCounter2").innerHTML = (115 - document.email.body.value.length);
}
</script>

<form name="email" method="post" action="/sent.asp">
   Your Name:<BR>
   <TEXTAREA onkeypress="return taLimit()" onkeyup="return taCount(myCounter1)"
   name=subject rows=1 wrap=physical cols=40 maxLength="13"></TEXTAREA><br>
   You have <B><SPAN id=myCounter1>13</SPAN></B> characters remaining.</font><BR>
   <BR>
   Your Message:<BR>
   <TEXTAREA onkeypress="return taLimit()" onkeyup="return taCount(myCounter2)"
   name=body rows=4 wrap=physical cols=40 maxLength="115"></TEXTAREA><br>
   You have <B><SPAN id=myCounter2>115</SPAN></B> characters remaining.</font><BR>
   <BR>
   <input type="submit" name="submit" value="Send Me A Text Message!">
  </form>


CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

mvidasAuthor Commented:
Thanks, I'll try that tonight or tomorrow morning when I get some time. Thanks!
kiddangerCommented:
This is not an ASP related question.  You'll get better response when you post in the correct areas.

This should do what you want.  I tested it in IE6 and FF1.0.4.

<%@ Language=VBScript %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script type="text/javascript">
function getcount(t, c) {
  var el = document.getElementById(t);
  var count = el.value.length;
  var max = el.getAttribute("maxlength") * 1;
  if(count > max) {
    el.value = el.value.substring(0, max);
    } else {
    document.getElementById(c).innerHTML = (max - count);
    }
  }
</script>
</HEAD>
<BODY>

<textarea rows="4" cols="40" id="ta1" maxlength="13" onkeyup="getcount(this.id,'counter1')"></textarea>
<div>You have <span id="counter1">13</span> characters left</div>
<textarea rows="4" cols="40" id="ta2" maxlength="115" onkeyup="getcount(this.id,'counter2')"></textarea>
<div>You have <span id="counter2">115</span> characters left</div>
</BODY>
</HTML>

Test page: http://kiddanger.com/lab/ee/q_21478000.asp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mvidasAuthor Commented:
Sorry about the delay, thanks to both of you.  I've got it working without a problem now.  I learned from both of them, so I'm going to increase this to 500 and give you each half.

Thanks again!
Matt
kiddangerCommented:
Thank you mvidas.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.