Capitalize text in entry field

jasonadal
jasonadal Community Member Posts: 441 ♪ Opening Act ♪
I'm attempting to set an entry field so that it capitalizes the first word anytime a user enters text. I did search the forum and found the posting "Controlling text entry form field", but when I click on the title from the search results, it doesn't open the thread (Jennifer?)

I saw the response from Sergey re: adding as a meta tag, tried that and was not able to get it to work. I also tried adding a custom class with a JS action or an document.getElement on the object (with the actual object name), both to no avail.

I found in one of the inline stylesheets that the element has ".input.entry338753" (the HTML name) and when I had the text-transform properties, it does work. I'm just not sure how to adjust that using an HTML element or RunJS action. Thanks for the help!

Comments

  • klaatu
    klaatu Community Member Posts: 988
    Here you go. Put this in an onChange Run JavaScript action on the entry text field. Remember to change the ID to the name of your entry text.

    document.getElementById("entry40id").value = document.getElementById("entry40id").value[0].toUpperCase() + document.getElementById("entry40id").value.substring(1);

    Darrel
  • jasonadal
    jasonadal Community Member Posts: 441 ♪ Opening Act ♪
    Thanks, Darren - that worked like a charm with one little caveat. When I enter a single letter, it doesn't update the variable itself until a second letter is entered (it does capitalize it right away on the screen, though). In this course, I need the learner to be able to enter a single letter in the field as part of a search screen emulation.

    In hindsight, maybe a question instead of a straight entry field may have been better, even if it meant setting up more conditional actions...
  • klaatu
    klaatu Community Member Posts: 988
    Ah, good catch. No worries. Where there's a will, there's a way.

    Add the following line after the code above:

    VarEntry_0001.set(document.getElementById("entry40id").value);

    Make sure the variable and ID match yours.

    Darrel
  • jasonadal
    jasonadal Community Member Posts: 441 ♪ Opening Act ♪
    Thanks again, Darren. Jennifer V - is there a coding hero badge you can bestow upon Darren and some others that have been absolutely bang-up on helping me and others with scripting?
  • jvalley4735
    jvalley4735 Community Member Posts: 1,357
    I tried to recreate the issue of you not being able to click on the link in the Community but no luck @JasonADal Can you tell me which browser and operating system you're using to access the site?
  • jasonadal
    jasonadal Community Member Posts: 441 ♪ Opening Act ♪
    @jvalley4735 It happened across multiple browsers (IE, Chrome and Firefox) on my Windows 7 desktop and laptop at work - I just tried again and I get to the page, but there's no thread. I can double check again from home tonight on my personal laptop and tablet as well.
  • jvalley4735
    jvalley4735 Community Member Posts: 1,357
    @JasonADal I'll bring it to our developer's attention to see if there's anything we can do on the back end.  If you get a chance would you mind taking a video (nothing fancy) or screenshots since I'm unable to recreate it? You can send them over to my email which is [email protected]