Javascript - Input string to Uppercase
Evening All,
Thanks so much for all the help so far - my experiment has come together like a dream. I have one last question about input and uppercase letters.
The participants are required to input multi character responses and I'm using the template here https://forum.cogsci.nl/discussion/4737/text-input-form-for-use-with-jatos#latest to save them as a string as independent variables.
However, as the answers may be in German (where they should be capitalised) I thought a work around would be to make all input appear in capitals. Later in the experiment their typed responses are shown to them again and it would look best if they were UPPERCASE.
I am totally new to javascript (and have zero other coding knowledge!) I am trying to get the string created using the code below to 'turn' the input uppercase. I see that there is a function toUppercase() but I don't know at which point to put this in.
I've included a screenshot of what I'm working with. Thanks for any pointers you can give :)
Ali
Comments
Hi Ali,
I think the easiest solution is to convert the strings to uppercase at the very end of the scripts, by adding something like the following line:
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi @sebastiaan,
Thanks for that! When I put it at the beginning (in line 2) it works beautifully also - except that the letter typed is displayed lowercase until the next letter is typed....
Do you know of a way to make the processing simultaneous so that all letters input show as capitals immediately?
I think for Germans it's quite counter-intuitive to type a noun and see it in lowercase and I don't want to distract them from inputting great words as responses!
Thanks again (again!)!
Ali
Hi @AliW ,
Do you know of a way to make the processing simultaneous so that all letters input show as capitals immediately?
Yes, by putting the line at the end of the script, as I suggested 😉
Do you know of a way to make the processing simultaneous so that all letters input show as capitals immediately?
The key thing is to make sure that the conversion to uppercase happens after the key press response is appended to the variable. Otherwise you'll get the behavior that you're describing, in which the keys are only converted to uppercase on the next input cycle.
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi @sebastiaan,
THANK YOU!! A fail on my part - In my eagerness I must've had a typo when I tried it at the end, as it didn't do anything first time round and "only worked when I tired it at the beginning"!
Second time trying it at the end it has worked wonderfully and does exactly what you said! And thank you for the explanation - getting my head around code is taking its time.
Cheers!
Ali