Skip to main content
Kinetic Community

How to build Ranking Questions

Import Files
Service Item RankingQuestions.zip
KURL Ranking Questions.rb
You may have a need to have your end users Rank some values from 1 to 5.  Of course you will need to ensure that your end user only selects each value one time.

Description

In the example attached to this article I am asking the end user to Rank their Favorite Northwest Division NHL Team's from 1 to 5.  To accomplish this I have created five List (Radio button) Questions one for each team (Calgary Flames, Colorado Avalanche, Edmonton Oilers, Minnesota Wild, and Vancouver Canucks).  Once completed I built five Javascript functions contained in the CustomHeaderContent (located on the Advanced tab).  The syntax is listed below:

<script>



function rankQuestion1()
{

     var value1=KD.utils.Action.getQuestionValue('Calgary Flames');
     var value2=KD.utils.Action.getQuestionValue('Colorado Avalanche');
     var value3=KD.utils.Action.getQuestionValue('Edmonton Oilers');
     var value4=KD.utils.Action.getQuestionValue('Minnesota Wild');
     var value5=KD.utils.Action.getQuestionValue('Vancouver Canucks');

if (value1 == value2 || value1 == value3 || value1 == value4 || value1 == value5 )

{
alert("Rank already selected please try again");
KD.utils.Action.setQuestionValue('Calgary Flames', null);
return false;
}
}


function rankQuestion2()
{

     var value1=KD.utils.Action.getQuestionValue('Calgary Flames');
     var value2=KD.utils.Action.getQuestionValue('Colorado Avalanche');
     var value3=KD.utils.Action.getQuestionValue('Edmonton Oilers');
     var value4=KD.utils.Action.getQuestionValue('Minnesota Wild');
     var value5=KD.utils.Action.getQuestionValue('Vancouver Canucks');

if (value2 == value1 || value2 == value3 || value2 == value4 || value2 == value5 )

{
alert("Rank already selected please try again");
KD.utils.Action.setQuestionValue('Colorado Avalanche', null);

return false;
}
}


function rankQuestion3()
{

     var value1=KD.utils.Action.getQuestionValue('Calgary Flames');
     var value2=KD.utils.Action.getQuestionValue('Colorado Avalanche');
     var value3=KD.utils.Action.getQuestionValue('Edmonton Oilers');
     var value4=KD.utils.Action.getQuestionValue('Minnesota Wild');
     var value5=KD.utils.Action.getQuestionValue('Vancouver Canucks');

if (value3 == value1 || value3 == value2 || value3 == value4 || value3 == value5 )

{
alert("Rank already selected please try again");
KD.utils.Action.setQuestionValue('Edmonton Oilers', null);

return false;
}
}


function rankQuestion4()
{

     var value1=KD.utils.Action.getQuestionValue('Calgary Flames');
     var value2=KD.utils.Action.getQuestionValue('Colorado Avalanche');
     var value3=KD.utils.Action.getQuestionValue('Edmonton Oilers');
     var value4=KD.utils.Action.getQuestionValue('Minnesota Wild');
     var value5=KD.utils.Action.getQuestionValue('Vancouver Canucks');

if (value4 == value1 || value4 == value2 || value4 == value3 || value4 == value5 )

{
alert("Rank already selected please try again");
KD.utils.Action.setQuestionValue('Minnesota Wild', null);

return false;
}
}


function rankQuestion5()
{

     var value1=KD.utils.Action.getQuestionValue('Calgary Flames');
     var value2=KD.utils.Action.getQuestionValue('Colorado Avalanche');
     var value3=KD.utils.Action.getQuestionValue('Edmonton Oilers');
     var value4=KD.utils.Action.getQuestionValue('Minnesota Wild');
     var value5=KD.utils.Action.getQuestionValue('Vancouver Canucks');

if (value5 == value1 || value5 == value2 || value5 == value3 || value5 == value4 )

{
alert("Rank already selected please try again");
KD.utils.Action.setQuestionValue('Vancouver Canucks', null);

return false;
}
}

</script>

 

Each of my five List Questions are calling one of the rankQuestion(1,2,3,4,or 5) functions.  The functions are setting a variable value for each one of the List Questions and are using the KD.utils.Action.getQuestionValue function to return the answers to these questions.  Once the answers are returned the function is checking to see if value is equal to any of the other answers.  If that returns a true then an Alert is displayed telling the end user to "try again" and also set the selected answer to a null value.  The setting to a null value is key because you want to ensure that each value is only selected once.  I have also created a Button in order to Clear Ranks for end user usability.  When this button is clicked I am setting each of the five questions to a Null value.


Attached to this article you will find a Survey called Ranking Questions.  This Survey can be imported into your Survey Environment.