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-95 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. - vv-ae7e971a-2793 years agoCommunity Member
Thak You so much I'ts working
- Jean-Christo2032 years agoCommunity Member
This actually worked, but now I have a question...
How to make it so spaces aren't counted as a character?
Related Content
- 11 months ago
- 8 months ago