Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Prevent a user (with token) from selecting a specific answer in a ranking questi

  • brisyb
  • brisyb's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 3 months ago #90134 by brisyb
I have a ranking question where a user can rank three players in a sports team from 1 to 3. What I want to do is prevent a user (say using the lastname in their token) from selecting themself from the list of answers. Each player is in the list.

I need to be able to compare the users LASTNAME with the answer to see if they match, and if they do, prevent the user from selecting that answer.

The comparison is easy, but i dont know how to code it so they cant select themself.
for example I know I should code if(TOKEN:LASTNAME == 'Smith', R1_4 ... but what comes next to stop them being able to select it?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 3 months ago - 11 years 3 months ago #90146 by tpartner
I'm assuming you are using LS 2.0.

It's not easy to disable a single item of a sortable list (ranking) but I think it may be more user-friendly to remove the item entirely anyway.

Try adding this to the source of the question. The script will remove the ranking item that contains the exact text as the LASTNAME attribute.
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() { 
 
    var lastName = '{TOKEN:LASTNAME}';
 
    $('.dragDropTable li').filter(function() {
      return $(this).text() == lastName;
    }).remove();
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 11 years 3 months ago by tpartner.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose