Difference between revisions of "Validate email specified as an open text of a single question"
m (→Solution) |
(→Script) |
||
Line 13: | Line 13: | ||
==Script== | ==Script== | ||
<source lang=javascript> | <source lang=javascript> | ||
− | var qLabel = " | + | var qLabel = "Question1";//question's label |
var openAnswerValue = 1;//the value of answer option which has open text | var openAnswerValue = 1;//the value of answer option which has open text | ||
var ErrorMessage_InvalidEmail = "Invalid email.";//error message in your needed language | var ErrorMessage_InvalidEmail = "Invalid email.";//error message in your needed language | ||
− | var | + | var normalQuestionCheck = questioncheck; |
− | + | function extendedQuestionCheck() | |
{ | { | ||
− | + | var valid = normalQuestionCheck(); | |
− | + | var email = $("input[name='QUESTION." + qLabel + ".Open." + openAnswerValue +"']").val(); | |
− | + | $(document).ready(function(){ | |
− | + | $("input:radio[name='QUESTION." + qLabel+"']").each(function(index) { | |
− | + | ||
− | + | if($(this).val() == openAnswerValue && email != ""){ | |
− | + | alert($(this).val()); | |
− | + | valid = validateEmail(email); | |
− | + | } | |
− | + | }); | |
− | + | }); | |
− | + | if (!valid) | |
+ | { | ||
+ | ErrorMessages.getInstance().showErrorMessage(ErrorMessage_InvalidEmail); | ||
+ | return false; | ||
+ | } | ||
+ | else | ||
+ | return true; | ||
} | } | ||
+ | questioncheck = extendedQuestionCheck; | ||
</source> | </source> |
Revision as of 13:55, 5 September 2011
Challenge
In order to secure my questionnaire's input
As a CGS writer
I want to validate an email specified as an open text of a single question
Example
Solution
- Add the script below to the question's Javascript property
- Locate the input text box and use validateEmail function to validate the email
Script
var qLabel = "Question1";//question's label
var openAnswerValue = 1;//the value of answer option which has open text
var ErrorMessage_InvalidEmail = "Invalid email.";//error message in your needed language
var normalQuestionCheck = questioncheck;
function extendedQuestionCheck()
{
var valid = normalQuestionCheck();
var email = $("input[name='QUESTION." + qLabel + ".Open." + openAnswerValue +"']").val();
$(document).ready(function(){
$("input:radio[name='QUESTION." + qLabel+"']").each(function(index) {
if($(this).val() == openAnswerValue && email != ""){
alert($(this).val());
valid = validateEmail(email);
}
});
});
if (!valid)
{
ErrorMessages.getInstance().showErrorMessage(ErrorMessage_InvalidEmail);
return false;
}
else
return true;
}
questioncheck = extendedQuestionCheck;