Changing the starting year on the Qualtrics date question | XM Community
Skip to main content

Changing the starting year on the Qualtrics date question

  • September 2, 2022
  • 6 replies
  • 821 views

Forum|alt.badge.img

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

6 replies

lizb311
Level 3 ●●●
Forum|alt.badge.img+20
  • Level 3 ●●●
  • 119 replies
  • September 2, 2022

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 1900
to  
var yearFirst = 1978; //min is 1978


Forum|alt.badge.img
  • Author
  • 5 replies
  • September 2, 2022

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')[0];
  var day=document.getElementsByName('QR~'+qid+'#2~1')[0];
  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.options[30].disabled=0;
    day.options[31].disabled=0; 
    if(mo.selectedIndex==2||mo.selectedIndex==4||mo.selectedIndex==6||mo.selectedIndex==9||mo.selectedIndex==11)
    {
      day.options[31].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.options[yr.selectedIndex].innerHTML,10)%4!=0)
        {
          day.options[29].disabled=1;
          if(day.selectedIndex==29){day.selectedIndex=28}; 
        }
        else
        {
          day.options[29].disabled=0;
        }      
      }
    }
  
  }
                                
  yr.onchange=function(){fixer();};
  mo.onchange=function(){fixer();};


    
});


lizb311
Level 3 ●●●
Forum|alt.badge.img+20
  • Level 3 ●●●
  • 119 replies
  • September 2, 2022

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.


Forum|alt.badge.img
  • Author
  • 5 replies
  • September 2, 2022

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


Forum|alt.badge.img
  • Author
  • 5 replies
  • September 2, 2022

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.
movinout1.jpgSo 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


lizb311
Level 3 ●●●
Forum|alt.badge.img+20
  • Level 3 ●●●
  • 119 replies
  • September 2, 2022

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