Forum Discussion
Limiting Text Entry to One Character
Hi Dawn,
This may not be the optimal way of doing what you asked, but here's some code which will set the Text Entry Field blank if more than one character is entered ("//" precedes code comments):
var player = GetPlayer(); //get the player
var Letter01 = player.GetVar("Letter01"); //get text entry field variable
if (Letter01.length > 1){ //if the length of Letter01 is greater than 1
player.SetVar("Letter01",""); //reset the variable to hold no value
}
You can add this JavaScript to a trigger, which will execute the script 'When control loses focus' on the Text Entry Field. The downside of this is that users can still enter as many characters as they like - until they click away - and this will display the vertical scroll bar on the Text Entry Field.
Another consideration would be some sort of character validation to ensure that users are only inputting a-z and A-Z, and not numbers or any other special characters.
I hope this is of some help to you!
Kind regards,
Doug
- DawnFriedel-9bd7 years agoCommunity Member
Thanks, Doug!
I know when coding HTML that you can set a maximum length to an input field. I was thinking along those lines. But I will try this and see how it goes.
Related Content
- 11 months ago
- 8 months ago