I want to change the maxlength of a textbox with JavaScript or jQuery: I tried the following but it didn't seem to help:
var a = document.getElementsByTagName('input'); for(var i=0; i<a.length; i++) { if((a[i].type!= 'radio')||(a[i].type!= 'checkbox')) a[i].maxlength = 5; } document.getElementsByTagName('input')[1].maxlength="3"; $().ready(function() { $("#inputID").maxlength(6); });
What am I doing wrong?
maxlength="3"; $(). ready(function() { $("#inputID"). maxlength(6); });
To give a limit to the input field, use the min and max attributes, which is to specify a maximum and minimum value for an input field respectively. To limit the number of characters, use the maxlength attribute.
The maxlength attribute defines the maximum number of characters (as UTF-16 code units) the user can enter into an <input> or <textarea> . This must be an integer value 0 or higher. If no maxlength is specified, or an invalid value is specified, the input or textarea has no maximum length.
Not sure what you are trying to accomplish on your first few lines but you can try this:
$(document).ready(function() { $("#ms_num").attr('maxlength','6'); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With