Retrieve data from survey-html-form #1260
-
Hello everyone, In an attempt to build a rudimentary version of a digit span test, I plan to present participants with an audio file and ask them to reproduce the digits by typing them into a survey-html-form. To check their performance, I need to compare the digits typed in by the participant with the ones stored in a js-file. Thus, what I hope to get store in the variable get_digits is just the digits that were typed in. Thanks a lot in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Here is a quick example.
The input name portion is missing quotes around it. |
Beta Was this translation helpful? Give feedback.
-
Hi Christina, var form_trial = {
type: 'survey-html-form',
preamble: '<p>Please, type in the digits you just heard in the correct order.</p>',
html: '<p><input name="digits" type="text"/></p>',
button_label: 'Submit',
on_finish: function(data) {
var data = JSON.parse(jsPsych.data.get().last(1).select('responses').values);
var get_digits = data["digits"];
console.log(get_digits);
}
} |
Beta Was this translation helpful? Give feedback.
Hi Christina,
The problem here is that the value of responses starts off as an object of key-value pairs (question names and text responses), and JavaScript objects can't be stored directly in the jsPsych data, so they have to be stored as a JSON-formatted text. So when trying to access the responses object, you just need to convert the JSON text back to JavaScript with
JSON.parse()
. Try this: