I have a question where users can select a time of day to set up an appointment. I am comparing the time in each option to the current system time, and want to remove it if it has already passed. For example, if it is 11:30am, then 9:00am, 10:00am, and 11:00am should be removed.
My code seems to be correctly identifying which options should be removed, but I'm having trouble actually removing the options.
// get system local time
var d = new Date();
var m = d.getMinutes();
var h = d.getHours();
if(h == '0') {h = 24}
var curr_time = h*60+m;
var qid = this.questionId;
var choice_contents = Qualtrics.SurveyEngine.QuestionInfo[qid].Choices;
var options = [];
Object.entries(choice_contents).forEach(item => {options.push(item[1]);})
options.forEach((item) =>{
var hr = item.Text.split(":")[0]*60;
if(item.Text.split(":")[1].includes("pm") && hr<720){hr +=720;}
var mn = hr + Number(item.Text.split(":")[1].replace(/\\D/g,""));
if(mn
}
})
I have seen the jQuery("#"+this.questionId+ ... .hide(); snippet of code that can remove options, but I don't know what conditions to use in this case.
Any suggestions? Thank you!
Solved
How to remove options from a question based on a condition?
Best answer by TomG
Two things:
- You need to use qid instead of this.questionId in your selector. 'this' no longer refers to the question object inside the forEach function.
- You've made it more complex by creating an object that separates your logic from the actual HTML element. However, I think this might work:
jQuery("#"+qid+" [choiceid="+item.VariableName+"]").closest("li").hide();
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
