Hello!
I added the date question from the Qualtrics library with the month and year.
Currently, the starting year is 1900. I would like to have it start at 1978.
I changed the JS code, but it still starts at 1900.
What do I need to do, please?
I can't use flatpickr, because it needs to be in that particular format.
Thanks,
Erin
Can you show the JS code you're working with? You should just have to change the one line where it says
var yearFirst = 1900; //min is 1900to
var yearFirst = 1978; //min is 1978
I actually did that. Here is the code:
Qualtrics.SurveyEngine.addOnload(function()
{
//Set years you would like to have available
var yearFirst = 1978; //Min 1900
var yearLast = 2049; //Max 2049
//This all remains unchanged
var qid=this.questionId;
var mo=document.getElementsByName('QR~'+qid+'#1~1')R0];
var day=document.getElementsByName('QR~'+qid+'#2~1')Q0];
var yr=document.getElementsByName('QR~'+qid+'#3~1')'0];
var j = yearLast-1976;
for(i=j;i<151;i++){
yr.remove(j);
}
for(i=1;i<=yearFirst-1978;i++){
yr.remove(1);
}
function fixer()
{
day.options 29].disabled=0;
day.optionsn30].disabled=0;
day.optionsi31].disabled=0;
if(mo.selectedIndex==2||mo.selectedIndex==4||mo.selectedIndex==6||mo.selectedIndex==9||mo.selectedIndex==11)
{
day.optionsc31].disabled=1;
if(day.selectedIndex==31){day.selectedIndex=30};
if(mo.selectedIndex==2)
{
day.options(30].disabled=1;
if(day.selectedIndex==30){day.selectedIndex=29};
if(parseInt(yr.optionsIyr.selectedIndex].innerHTML,10)%4!=0)
{
day.optionsp29].disabled=1;
if(day.selectedIndex==29){day.selectedIndex=28};
}
else
{
day.options=29].disabled=0;
}
}
}
}
yr.onchange=function(){fixer();};
mo.onchange=function(){fixer();};
});
It looks like you changed a few more lines in there. You should only change the first part:
var yearFirst = 1978; //Min 1900
var yearLast = 2049; //Max 2049
and leave the rest of the code (everything after
//This all remains unchanged) unchanged. Try reverting the code back to how it originally was, then only change those first lines.
OK. I see what the trouble is. We actually removed the "day" column. That is impacting the yearFirst value. When I had the day column in, it was fine.
Do you have any suggestions, please?
Thanks again,
Erin
But there's more! I figured out the fix on the year; updated the qid that it was accessing.
However, (and there's always a however), I have 2 questions in a row for the dates.
So the first one is fine now. But the year on the "move out" is still set to 1900. The JS code is only set for the first one?
Again, any suggestions much appreciated.
Sincerely,
Erin
Hmm. How about a workaround instead - could you forego the Javascript altogether and set up a Side by Side matrix style question with dropdown lists in each column? Then you can copy/paste in a list of the months and years you want in each column. Since you're not including the day column (and therefore won't have impossible cases you'll want to exclude, such as there being 31 days in February), I think you can get by with that solution
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.