Web Analytics Made Easy -
StatCounter getAttribute with "this" - CodingForum

Announcement

Collapse
No announcement yet.

getAttribute with "this"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • getAttribute with "this"

    help,

    i make function like this:

    function chrCount(which){
    maxChr = document.getElementById(which.name).getAttribute('maxlength');
    if (which.value.length > maxChr)
    which.value = which.value.substring( 0 , maxChr )
    else
    document.getElementById('chrLeft').innerHTML = maxChr-which.value.length + " chr(s)Left" ;
    }

    html code:

    <input name="name" type="text" maxlength="8" onKeyDown="chrCount(this)" onKeyUp="chrCount(this)">
    <div id="chrLeft" ></div>

    above code work in IE6, not in Mozilla, can anybody tell the right code ? running in IE6 and DOM browser only is find.
    Thanks

  • #2
    You are passing getElementById a name, not an id. Huge difference in terms of DOM.

    Anyway, since you're passing the this reference:
    maxChr = which.getAttribute('maxlength');

    Is much clearer, faster, and less haphazard.
    jasonkarldavis.com

    Comment


    • #3
      u r right!!! Why was I so stupid!! thx a lots...

      Comment

      Working...
      X