This script will allow you to hide the day and/or month in a Date question. The default Date question prompts for month, day and year.
Note:
- This script does not work with mobile view because of the use of JavaScript.
- This script does not work when the property Question Completion Required is not set or ticked.
Example
- You want to ask participants "When was your last oil change?" It may be inappropriate to ask for the exact date as the participant may not remember, so you ask the participant to choose the month and year only.
- You want to ask participants "What year is your family sedan?" You only require the year, so day and month will be hidden.
Detailed Steps
- Create a Date question as required.
- Copy one of the two scripts below (based on your requirement) into Notepad or any other text editor (e.g. Notepad++, Textpad).
- Change QNAME to the name of your Date question.
- Insert the completed script into the Script section of the date question by doing the following:
- Select the Date question in the Questionnaire Tree.
- In the Scripting section of the page, click Edit Scripts.
- Paste the script into the JavaScript tab.
- Click Save.
- Click Validate and test your survey.
Hide Day Only
<script src="https://static.visioncritical.net/prog/ext_libs/jquery/jquery-1.12.3.min.js" type="text/javascript">
/* Script Name: How do I hide the day and/or month in a Date question? To ensure your script works as expected, always copy the original script from the script library found in the support portal. Failure to use the most up to date script from the script library may cause unexpected results. */
</script><SCRIPT>
hideDay([%(QNAME.Id)%]);
/************ Do not edit below ************/
function hideDay(e){
$j=jQuery.noConflict();
$j(document).ready(function(){ hideDayAndMonth_Helper(e,true,false)})
}
function hideDayAndMonth(e){
$j=jQuery.noConflict();
$j(document).ready(function(){ hideDayAndMonth_Helper(e,true,true)})
}
function hideDayAndMonth_Helper(e,t,n){
function u(){
var e=false;
if(s.find("option:selected").index()>0){e=true}
if(!n&&i.find("option:selected").index()>0){e=true}
if(!t&&r.find("option:selected").index()>0){e=true}
$j.each(o,function(){ this.find("option").eq(1).prop("selected",e)})
}
var r=$j("#i"+e+"VerbatimQuestion_Day");
var i=$j("#i"+e+"VerbatimQuestion_Month");
var s=$j("#i"+e+"VerbatimQuestion_Year");
var o=[];
if(r.length>0&&t){ r.hide();o.push(r)}
else{ r.change(u) }
if(i.length>0&&n){i.hide();o.push(i)}
else{i.change(u)}
s.change(u)
}
var $j
</SCRIPT>
Hide Day and Month
<script src="https://static.visioncritical.net/prog/ext_libs/jquery/jquery-1.12.3.min.js" type="text/javascript">
/* Script Name: How do I hide the day and/or month in a Date question? To ensure your script works as expected, always copy the original script from the script library found in the support portal. Failure to use the most up to date script from the script library may cause unexpected results. */
</script><SCRIPT>
hideDayAndMonth([%(QNAME.Id)%]);
/************ Do not edit below ************/
function hideDay(e){
$j=jQuery.noConflict();
$j(document).ready(function(){ hideDayAndMonth_Helper(e,true,false)})
}
function hideDayAndMonth(e){
$j=jQuery.noConflict();
$j(document).ready(function(){ hideDayAndMonth_Helper(e,true,true)})
}
function hideDayAndMonth_Helper(e,t,n){
function u(){
var e=false;
if(s.find("option:selected").index()>0){e=true}
if(!n&&i.find("option:selected").index()>0){e=true}
if(!t&&r.find("option:selected").index()>0){e=true}
$j.each(o,function(){ this.find("option").eq(1).prop("selected",e)})
}
var r=$j("#i"+e+"VerbatimQuestion_Day");
var i=$j("#i"+e+"VerbatimQuestion_Month");
var s=$j("#i"+e+"VerbatimQuestion_Year");
var o=[];
if(r.length>0&&t){ r.hide();o.push(r)}
else{ r.change(u) }
if(i.length>0&&n){i.hide();o.push(i)}
else{i.change(u)}
s.change(u)
}
var $j
</SCRIPT>
More Information
For more information, see our WebHelp topic Date question.
Comments
0 comments
Article is closed for comments.