[Solved] Can you add validation to a Slider List?

0

I am building a survey which includes a Slider list, I would like the survey to check whether the summation of the slider lists equals 100 and only allow people to go to the next question once 100 has been reached. Is this possible?

Julia Turner asked

    Best answer

    0

    Hey Julia,

    What about something like what I have set up here: http://www.surveygizmo.com/s3/2548408/slider-list-validation

    I’m using this script to do that:

    $(document).ready(function(){

    //this section outputs the total to the page
    $(“#sgE-2548408-1-5-box”).change(function(){
    var slider1 = $(“#sgE-2548408-1-5-10001”).val()*1; //get value of sliders
    var slider2 = $(“#sgE-2548408-1-5-10002”).val()*1;
    var slider3 = $(“#sgE-2548408-1-5-10003”).val()*1;
    var slider4 = $(“#sgE-2548408-1-5-10004”).val()*1;
    var sum = slider1 + slider2 + slider3 + slider4; //add up all values
    $(“.sum”).text(sum); //sets text in “total” span on page to their total so far
    });

    //this section checks the total when the page is submitted
    $(“#sg_FormFor2548408”).submit(function(e){
    var slider1 = $(“#sgE-2548408-1-5-10001”).val()*1; //get value of sliders
    var slider2 = $(“#sgE-2548408-1-5-10002”).val()*1;
    var slider3 = $(“#sgE-2548408-1-5-10003”).val()*1;
    var slider4 = $(“#sgE-2548408-1-5-10004”).val()*1;
    var sum = slider1 + slider2 + slider3 + slider4; //add up all values
    if (sum != 100) {
    alert(“Please make sure that your sliders add up to 100”);
    return false;
    e.preventDefault;
    }
    });

    });

     

    If you or anyone on your team know Javascript / jQuery, this should help you get started in the right direction!

    Elizabeth Rose answered
      0

      That’s perfect thank you.

      Julia Turner answered
        ×

        Login

        Question stats

        • Active
        • Views1280 times
        • Answers2 answers
        • Followers0 followers