Update image src onclick for subsequent trials #2957
Unanswered
jaimielee97
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I’m coding an experiment with a 12x12 grid of image buttons in jsPsych. Participants receive feedback based on which squares they choose to click. These squares are all initially white (saved as an img file called “old”) but after a square has been clicked I want it to turn grey (img file called “new”) for all subsequent trials (100 total). To do this, I’ve been trying to get the src of a button to update after it has been clicked.
I was able to change the image on an individual trial using advice from Q&A #1931. The trial normally ends upon click, but I turned that off and was able to see the square change to grey after it was clicked. However, all the squares revert back to white after participants see the feedback screen and then return to the grid for the next trial.
To try and fix this so the colour change carried over for all future trials, I made the button_html a function and included an on_finish function that goes through all the squares and updates them to grey if they are included in the "clicked squares" array. However, this gives an error "Uncaught TypeError: Cannot set properties of null (setting 'src')". I'm not sure why it can't find the images to update the src, or if there's a better way to go about this. Any advice would be greatly appreciated, thank you!
Beta Was this translation helpful? Give feedback.
All reactions