Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We've got SP2010 foundation, and the other limitation is that we do not have access to SPD or any of the programmatic ways of accomplishing this. I'm looking for information about how to set this up in a validation formula on the survey settings page.

We're using a survey as a checkpoint quiz after a training session, and each question has a three-choice radio button with one correct answer. We are trying to validate the correct answers, and ONLY advance users to the next question when they answer correctly.

For instance:

What is 1+1?             Today is
O  1            -or-      O  Monday
O  2                      O  Tuesday
O  3                      O  Wednesday

Validation Formulae:
=[What is 1+1]="2"       =[Today is]="Monday"

My expected result is that when "2" or "Monday" are selected from the respective lists, validation passes and the survey advances to the next question. If the choice does not validate, a default "please try again" message will prompt the user until the correct selection is made.

However, using this approach, I get an ERROR: List validation failed dialog box no matter which answer I select in a survey question. Is there a way to evaluate the selected value in a formula?

share|improve this question
add comment

1 Answer

I would recommend using jQuery validation to accomplish this... please see the following links:

http://docs.jquery.com/plugins/Validation http://tinyurl.com/cn6objo

Here is a more concrete example:

Add a Content Editor Webpart (Set IsVisible to false) to your page Inside, include jQuery and jQuery.Validate scripts

//Checks for valid form on save
//Pass this function the validator object you create and the value of the save button
function CheckValidation(val,btn)
{
    $("input[value='" + btn + "']").each(function(){
        var js = $(this).attr("onclick");
        $(this).attr("onclick", "");
        $(this).click(function(event){
            if(!val.form()) { return false; }
            else { eval(" ( function () {" + js + " })();")};
        });
    });
}

//Pass this function the display name of your field, the value of the correct answer
//and the error message to display
function ToggleValidator(field,answer,msg)
{
    $("[title='" + field + "']").rules("add", {
        equalTo: answer,
        messages: {
            equalTo: msg
        }
    }); 
}   

$(function(){
    //Add validation to the form
    var val = $("#aspnetForm").validate({ 
                    errorClass: "ms-formvalidation"
                });                 

    //Add one for each field
    ToggleValidator("Your Field Name","Answer","Incorrect");

    CheckValidation(val, "Save");

});
share|improve this answer
    
Updated to include sample code, sorry about that! –  Dom Rocco Apr 10 '13 at 11:42
    
Thanks for updating - now a +1 answer :-) –  SPDoctor Apr 10 '13 at 13:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.