As in the title, I want to get the times when a user first starts typing something into an input box. And I want to do this for every input box in the question page.
I know how to access inputText—you could use
jQuery(".InputText")
but the problem is, I have two input texts on the same page, and it seems like jQuery .InputText doesn't differentiate between the two.
So I tried the following,
but the input1time and input3times 'saved' to my data spreadsheet are empty. In fact, the two codes/functions don't even run, as I've tried printing out to the console from both those functions (and nothing showed). How could I fix this?
var choice1entered = false;
var input1time;
this.getChoiceValue(1).onkeydown = function() {
if (!choice1entered) {
input1time = Date.now();
choice1entered = true;
}
};
var choice3entered = false;
var input3time;
this.getChoiceValue(3).onkeydown = function() {
if(!choice3entered) {
input3time = Date.now();
choice3entered = true;
}
};
document
.querySelector(".InputText")
.addEventListener(
"input",
() => Qualtrics.SurveyEngine.setEmbeddedData("first_input_time", Date.now()),
{ once: true }
);
ahmedA thank you for your response, but doesn't that just save the very first time I enter something into the InputText?
I want to make sure I save the first time I enter something into each textbox (of which there are two, but both are somehow joined together into a single ".InputText", and I want to name the two different times with different variables), so I think I should be having two different setEmbeddedData calls?
In other words, I would like to get the time and store it whenever the user switches between two text input boxes.
Is there a way to use choiceId along with .InputText, maybe?
Okay.
This was assuming only one input text box. I would then recommend using ids instead of the inputtext class.
Just Google how to find the ID of an element, change queryselector to getelementbyid, duplicate the event listener and you should be sorted.
ahmedA From my search it seems you'd need attr('id') used on jQuery(#____), but I'm not sure what follows the hash, since I still don't know how to query select for a specific input. could you help?
I thought perhaps what I saw in the spreadsheet would be the id, and tried this, but that doesn't work, either.
document
.getElementById("Q36_3")
.addEventListener(
"input",
() => Qualtrics.SurveyEngine.setEmbeddedData("input3_time_fruits", Date.now()),
{ once: true }
);
Preview Survey --> right click on text box --> select inspect --> in the inspector you'll see id="...."
Use this id value inside getElementById. Also, you'll need one for each text box.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.