Hi,
We are using javascript to determine the second question of a 1-page survey. To do this I have to make the second questions (there are 2 possibilities) non-mandatory.
Is there any way to set the mandatory flag using javascript on the survey?
Thanks
Lorna
Answer
Hi Lorna,
I do not know if there is a way to set the flag dynamically, but I was able to dynamically show questions which are mandatory and not affect the submission of the survey when those questions are not shown. In this survey I am asking if they have taken their machine to the Service center. If they answer no, then they get a text box to explain why not, and can submit the survey with no issues. If they say yes, they get the other questions and the first two in that string are required. (I have other dynamic sections as well, but the two questions I highlighted are the only required ones.) I hope this helps.
Regards,
Jess
<span style="FONT-SIZE: 18pt; FONT-FAMILY: Arial" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><span>Welcome to the Service Center Survey</span></span>
<p xmlns:xsd="http://www.w3.org/2001/XMLSchema"></p>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
//<![CDATA[
function ShowContent(e)
{
if(e == "335") {document.getElementById('q138').style.display = "none" ;
document.getElementById('ASC').style.display = "block" ; return true;}
if (e == "336") {document.getElementById('q138').style.display = "block" ;
document.getElementById('ASC').style.display = "none" ; return true;}
if(e == "72") {document.getElementById('q43').style.display = "none" ;return true;}
if (e == "73") {document.getElementById('q43').style.display = "block" ;return true;}
if(e == "74") {document.getElementById('q44').style.display = "none" ;return true;}
if (e == "75") {document.getElementById('q44').style.display = "block" ;return true;}
if(e == "78") {document.getElementById('q46').style.display = "none" ;return true;}
if (e == "79") {document.getElementById('q46').style.display = "block" ;return true;}
if(e == "84") {document.getElementById('q142').style.display = "none" ;return true;}
if (e == "85") {document.getElementById('q142').style.display = "block" ;return true;}
if(e == "86") {document.getElementById('q143').style.display = "none" ;return true;}
if (e == "87") {document.getElementById('q143').style.display = "block" ;return true;}
if(e == "88") {document.getElementById('q144').style.display = "none" ;return true;}
if (e == "89") {document.getElementById('q144').style.display = "block" ;return true;}
}
//]]>
</script>
<rn:question onchange="ShowContent(this.value)" version="3" split="False" question_id="137">Taken</rn:question>
<div id="q138" style="DISPLAY: none">
<rn:question version="3" split="False" question_id="138">Taken Explain</rn:question>
</div>
<div id="ASC" style="DISPLAY: none">
<rn:question version="3" split="False" question_id="139">ASC NPS</rn:question>
<rn:question version="3" split="False" question_id="141">ASC NPS Explain</rn:question>
<rn:question onchange="ShowContent(this.value)" version="3" split="False" question_id="24">Easily Found</rn:question>
<div id="q43" style="DISPLAY: none">
<rn:question version="3" split="False" question_id="43">Easily Found reason</rn:question>
</div>
<rn:question onchange="ShowContent(this.value)" version="3" split="False" question_id="25">Maintained</rn:question>
<div id="q44" style="DISPLAY: none">
<rn:question version="3" split="False" question_id="44">Maintained Reason</rn:question>
</div>
<rn:question onchange="ShowContent(this.value)" version="3" split="False" question_id="27">Knowledgable</rn:question>
<div id="q46" style="DISPLAY: none">
<rn:question version="3" split="False" question_id="46">Knowledgeable Reason</rn:question>
</div>
<rn:question version="3" split="False" question_id="29">Solution</rn:question>
<rn:question onchange="ShowContent(this.value)" version="3" split="False" question_id="30">Time frame</rn:question>
<div id="q142" style="DISPLAY: none">
<rn:question version="3" split="False" question_id="142">Time frame Explain</rn:question>
</div>
<rn:question onchange="ShowContent(this.value)" version="3" split="False" question_id="31">On time</rn:question>
<div id="q143" style="DISPLAY: none">
<rn:question version="3" split="False" question_id="143">On time explain</rn:question>
</div>
<rn:question onchange="ShowContent(this.value)" version="3" split="False" question_id="32">Working</rn:question>
<div id="q144" style="DISPLAY: none">
<rn:question version="3" split="False" question_id="144">Working explain</rn:question>
</div>
<rn:question version="3" split="False" question_id="33">Charged</rn:question>
</div>
Be the first to rate this
|
Sign in to rate this
Hi Jess,
My javascript is almost the same I just did it inline instead of in a function... but just because I doubt myself with these things, I changed it all to your function and tried again. I still get the error to say the question is mandatory and hasn't been completed.
<script language="JavaScript" type="text/javascript" xml:space="preserve">
//<![CDATA[
function ShowContent(e)
{
console.log(e);
//dsat
if(e == "5404" || e == "5405" | e == "5406") {
document.getElementById('q210').style.display = "none" ;
document.getElementById('q220').style.display = "block" ; return true;}
//csat
if (e == "5407" | e == "5408") {
document.getElementById('q210').style.display = "block" ;
document.getElementById('q220').style.display = "none" ; return true;}
}
//]]>
</script>
<rn:question question_id="1323" split="False" version="3" onchange="ShowContent(this.value)">Q100</rn:question>
<div id="q210" style="DISPLAY: none">
<rn:question question_id="1351" split="False" version="3" onchange="ShowContent(this.value)">Q210</rn:question>
</div>
<div id="q220" style="DISPLAY: none">
<rn:question question_id="1352" split="False" version="3" onchange="ShowContent(this.value)">Q220</rn:question>
</div>
<rn:question question_id="1341" split="False" version="3">QResolved</rn:question>
<rn:question question_id="1350" split="False" version="3">Q600</rn:question>
Be the first to rate this
|
Sign in to rate this
Lorna,
I tested mine again and now it is not working. I do not know why it worked previously. I am out of ideas, sorry. Maybe I had some other code, or maybe someone else set the requirement on the question.
Be the first to rate this
|
Sign in to rate this
Ah that's annoying - more for you than me, I suppose ;) Thanks for checking it though!
Be the first to rate this
|
Sign in to rate this
Why not setting up a survey inside the existing survey?

Like
Then between 1 and 2 add a condition based on 1 questions. Then according to what customers select then make 2 show next questions required and/or add a 3rd to show questions not required.
Cheers!!
Be the first to rate this
|
Sign in to rate this
Hi Efrain,
We wanted it all on one page. If I understand your suggestion it would mean having 2 pages, right?
Thanks
Be the first to rate this
|
Sign in to rate this