More actions
New page: == Challenge == You want to use automatically change question, but don't want to show the counter for the respondent. The Next button is often hided when this script is used. == Script ==... |
No edit summary |
||
Line 1: | Line 1: | ||
== Challenge == | == Challenge == | ||
You want to | You want to force the respondent to write a certain number of characters in a text sub question. The script is often used together with the Number grid script, to force the respondent to write a zip code, or a phone number in a certain text field | ||
== Example == | |||
[[Image:ValidateTextLength.JPG ]] | |||
== Script == | == Script == | ||
<source lang="javascript" line="1"> | <source lang="javascript" line="1"> | ||
function | var normalQuestionCheck = questioncheck; | ||
{ | function extendedQuestionCheck() | ||
document["query"][" | { | ||
var valid = normalQuestionCheck(); | |||
if (valid) | |||
{ | |||
// var_a hold the respondents answer. | |||
var var_a; | |||
// This is where the index of your sub question is defines. | |||
// The code below is that we use sub question has index 0 | |||
var_a = document["query"][quest.label + "." + 0].value; | |||
if (var_a.length > 0) | |||
{ | |||
if (var_a.length != 10) | |||
{ | |||
alert('The field can only hold 10 characters.'); | |||
return false; | |||
} | |||
} | |||
} | |||
if (!valid) | |||
{ | |||
alert('Please correct your answer.'); | |||
return false; | |||
} | |||
return true; | |||
} | } | ||
questioncheck = extendedQuestionCheck; | |||
</source> | </source> |
Revision as of 09:54, 2 March 2009
Challenge
You want to force the respondent to write a certain number of characters in a text sub question. The script is often used together with the Number grid script, to force the respondent to write a zip code, or a phone number in a certain text field
Example
Script
var normalQuestionCheck = questioncheck;
function extendedQuestionCheck()
{
var valid = normalQuestionCheck();
if (valid)
{
// var_a hold the respondents answer.
var var_a;
// This is where the index of your sub question is defines.
// The code below is that we use sub question has index 0
var_a = document["query"][quest.label + "." + 0].value;
if (var_a.length > 0)
{
if (var_a.length != 10)
{
alert('The field can only hold 10 characters.');
return false;
}
}
}
if (!valid)
{
alert('Please correct your answer.');
return false;
}
return true;
}
questioncheck = extendedQuestionCheck;