| Reference | Downloads | Github

Text Input function works locally but not online

Description of the problem:
I built an experiment where the participants can type in words and then see the written words on the screen. Therefore, I used this example experiment for text input:

It works perfectly fine on my computer, but as soon as I upload the experiment and try to run it online, I get the following error message:

TypeError: undefined is not an object (evaluating ‘event.getKeys’)

I don’t know how to solve it as if I delete or modify the part “event.getKeys” in the code, the experiment does not run anymore.

Do you have an idea of how I can fix this Error?

Here is my code:

Begin Routine:
modify = False
text.text = ‘’

Each Frame:
keys = event.getKeys()
if len(keys):
if ‘space’ in keys:
text.text = text.text + ’ ’
elif ‘backspace’ in keys:
text.text = text.text[:-1]
elif ‘lshift’ in keys or ‘rshift’ in keys:
modify = True
elif ‘return’ in keys:
continueRoutine = False
if modify:
text.text = text.text + keys[0].upper()
modify = False
text.text = text.text + keys[0]

End Routine:
thisExp.addData(“typedWord”, text.text)

@Mel499, take a look at the code repository of the working text input demo, and compare the difference between your code and the code of the demo. This should highlight where the error may be.

@dvbridges I have the exact same code as in this demo and it also works on my computer but I still receive an error message when trying to run the code online. Do you have any idea why this error message still occurs?

@Mel499 Came across this post as I’m having the same issue, did you ever find a way to resolve it? Thanks!

@KtS Unfortunately, I didn’t find a solution for the problem. In the end, I used another website for the text input. Sorry that I can’t help…

@Mel499 No problem! Thanks anyway, I’m glad you found something that works!

Hi all, I also have this issue. The problem is I can’t see the words I typed online, but they are saved in the results. Does anyone know how to fix this? Thank you.

I am encountering a similar problem with this code, but get no error message. It runs on Psychopy, but once uploaded to Pavlovia it gets stuck on “initialising the experiment…”

I am not sure if you have figured this out, but you can define the text input as a blank space. When the code translated into JS, the text input is read as None, and thus cause a syntax issue in the online experiment.


Many thanks for taking a look.
I had already tried the blank space option - that is the line…
text.text = ’ ’
… in the “Begin Routine” tab of the code snipet.
This woudn’t sync for some reason (“unhandled internal error”), but if I put some non-whitespace in did sync, but it still hung on “Initialising the experiment…” in Pavlovia.

Going round in circles here…


You can copy paste the code component in the demo of inputText, I think the important thing is that you should also copy paste the code in the JS panel when you choose “Both” in the code component so that it can overwrite the auto-translation. The auto-translation from Python to JS does not work very well for this.

Thanks Kuriko, I have done this and also adopted the habit of editing the js code after syncing as suggested by JensBoelte.

This gets past the problem of hanging on “initialising the experiment…”

However, after collecting a particpant name, it instantly comes back with another error…
" ReferenceError: assignment to undeclared variable frameDur "
I tried abandoning using the TextInput code and used the Textbox component instead, having set that up to work on PsychoPy, I was mortified to encounter all the same problems - I still had to edit the js code and it still came back with the frameDur error.



when editing the html-code by hand, I got the same Reference error. In the end, I initialised the string with a dummy text. This worked for me.

Cheers Jens