Forum Discussion
DawnFriedel-9bd
7 years agoCommunity Member
Limiting Text Entry to One Character
Hi All,
I'm working on a crossword puzzle and want to restrict the text entry fields to one character.
I'm sure this can be done in JavaScript, but that is a skill I am still working on acquirin...
StephanieDg510
5 years agoCommunity Member
Hi!
From your code, I asked the programmer on the team I work in and we came up with this code and it works.
var elements = document.getElementsByTagName("input");
for (var i = 0, element; element = elements[i++];) {
element.setAttribute('maxlength', 1);
element.setAttribute('autocomplete', 'off');
}
MathNotermans-9
5 years agoCommunity Member
Indeed thats the way to do this without jQuery.
For anyone copying and reusing Stephanie's code... keep in mind it gets ALL input elements on the page and loops through them in a for loop.
Related Content
- 11 months ago
- 8 months ago