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.QuestionInfocqid].Choices;
var options = ]];
Object.entries(choice_contents).forEach(item => {options.push(itemE1]);})
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(":")b1].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!
Page 1 / 1
Why are you asking the same question again? If you're choosing to pick up the solution from the previous question and it's not working, why aren't you asking over there itself?
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();
TomG Awesome, that worked! I was changing the Variable Names for the options, which was causing your code to not work. Once I changed them back to 1,2,3,4, etc., it worked just fine.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.