Difference between revisions of "Hide Next button in n seconds"

From Catglobe Wiki
Jump to: navigation, search
Line 1: Line 1:
 
== Challenge  ==
 
== Challenge  ==
  
In order to not allow respondent click on the Next button in a period of t<br>As a questionnaire creator<br>I want to hide the Next button in some seconds&nbsp;
+
In order to not allow respondent click on the Next button in a period of t<br>As a questionnaire creator<br>I want to hide the Next button in some seconds&nbsp;  
  
 
== Solution  ==
 
== Solution  ==
  
*In questionnaire template editor, choose the&nbsp;question&nbsp;I want to hide the Next button,&nbsp;and then&nbsp;go to the Properties - Edit question properties - Language dependent - Select javascript property&nbsp;
+
*In questionnaire template editor, choose the&nbsp;question&nbsp;I want to hide the Next button,&nbsp;and then&nbsp;go to the Properties - Edit question properties - Language dependent - Select javascript property&nbsp;  
*Create a onInit() function.
+
*Create a onInit() function.  
*In that function, check if the Next button existed.&nbsp;
+
*In that function, check if the Next button existed.&nbsp;  
 
*If it doesn't exist, do nothing, else disable the Next button, set the time&nbsp;out to number of seconds&nbsp;I want to hide the&nbsp;button, then show the button again.&nbsp;&nbsp;
 
*If it doesn't exist, do nothing, else disable the Next button, set the time&nbsp;out to number of seconds&nbsp;I want to hide the&nbsp;button, then show the button again.&nbsp;&nbsp;
  
 
== Code  ==
 
== Code  ==
  
<onlyinclude>quest.onInit = function()
+
&lt;source lang="javascript" line="1"&gt;quest.onInit = function()<br>{<br>var secsTimeout = 10;
{
+
 
var secsTimeout = 10;
+
if ( !document.getElementsByName('next') || document.getElementsByName('next').length == 0 ) <br>{<br>// next button not available<br>return;<br>}<br>else<br>{<br>document.getElementsByName('next')[0].style.display='none';<br>}
if ( !document.getElementsByName('next') || document.getElementsByName('next').length == 0 )  
+
 
{
+
var timeout = setTimeout("document.getElementsByName('next')[0].style.display='';", secsTimeout*1000);
// next button not available
+
 
return;
+
}&lt;/source&gt;
}
 
else
 
{
 
document.getElementsByName('next')[0].style.display='none';
 
}
 
var timeout = setTimeout("document.getElementsByName('next')[0].style.display='';", secsTimeout*1000);
 
}</onlyinclude>
 

Revision as of 05:09, 12 February 2009

Challenge

In order to not allow respondent click on the Next button in a period of t
As a questionnaire creator
I want to hide the Next button in some seconds 

Solution

  • In questionnaire template editor, choose the question I want to hide the Next button, and then go to the Properties - Edit question properties - Language dependent - Select javascript property 
  • Create a onInit() function.
  • In that function, check if the Next button existed. 
  • If it doesn't exist, do nothing, else disable the Next button, set the time out to number of seconds I want to hide the button, then show the button again.  

Code

<source lang="javascript" line="1">quest.onInit = function()
{
var secsTimeout = 10;

if ( !document.getElementsByName('next') || document.getElementsByName('next').length == 0 )
{
// next button not available
return;
}
else
{
document.getElementsByName('next')[0].style.display='none';
}

var timeout = setTimeout("document.getElementsByName('next')[0].style.display=;", secsTimeout*1000);

}</source>