change button picture onclick #1931
-
Hello, I have an arrary of 9 pictures, and I would like to have the picture that the user clicks on change to a different picture. With the following code, there is no error, but also no change in the picture. From an alert() call in the color() function I can also see that it is not accessing the correct %choice% picture, although the src element does appear to be changed. Is this possible in the experiment code, or does it require a change to the plugin itself?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hmm, your code is working fine for me! I created 4 images to test this: 'dog-old.gif', 'dog-new.gif', 'boat-old.gif', and 'boat-new.gif'. I also set So the code below is working for me. If I click on one of the buttons before the 5 second trial duration is up, then I see the button image change. var grid_buttons = {
type: 'html-button-response',
stimulus: '',
choices: ['dog','boat'],
button_html: '<button onclick = "color()"><img id="change" src="%choice%-old.gif"></button>',
prompt: 'Please click on a picture',
response_ends_trial: false,
trial_duration: 5000
}
function color(){
document.getElementById('change').src = document.getElementById('change').src.replace("old","new");
};
jsPsych.init({
timeline: [grid_buttons],
on_finish: function(){jsPsych.data.displayData();}
}); |
Beta Was this translation helpful? Give feedback.
Hmm, your code is working fine for me! I created 4 images to test this: 'dog-old.gif', 'dog-new.gif', 'boat-old.gif', and 'boat-new.gif'. I also set
response_ends_trial
tofalse
andtrial_duration
to 5 seconds, so that the trial doesn't end as soon as a button is clicked. Finally, I took thebutton_html
string out of a function (it does work the same way inside of a function, it just doesn't need to be inside of one).So the code below is working for me. If I click on one of the buttons before the 5 second trial duration is up, then I see the button image change.