Mikulas Dite
Mikulas Dite

Reputation: 7941

Removing the maxlength attribute

is it possible to remove a maxlength attribute from an element? I thought that setting it to 0 would work, but it seems like FF4 then prevents entering anything. http://jsfiddle.net/hMc4y/

I've heard that setting it to -1 does trigger an error and removeAttribute does not work either.

Upvotes: 6

Views: 8673

Answers (2)

maerics
maerics

Reputation: 156434

Using "removeAttribute('maxLength')" should work fine; perhaps the surprise is that the attribute name must be "maxLength" with an uppercase "L". Consider:

<form name="f">
  <input name="t" type="text" maxlength="5"/>
</form>
<script type="text/javascript">
  var t = document.f.t;
  alert(t.maxLength); // 5
  t.removeAttribute('maxLength');
  alert(t.maxLength); // 524288 (on Chrome/10.0.648.134)
</script>

Upvotes: 7

duri
duri

Reputation: 15351

removeAttribute works for me in both Firefox 3.5 and Chrome.

Upvotes: 2

Related Questions