Welcome, Guest
Username: Password: Remember me

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

Prevent a user (with token) from selecting a specific answer in a ranking questi 1 year 9 months ago #90134

  • brisyb
  • brisyb's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
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 administrator has disabled public write access.

Re: Prevent a user (with token) from selecting a specific answer in a ranking questi 1 year 9 months ago #90146

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4207
  • Thank you received: 791
  • Karma: 360
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.
<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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 1 year 9 months ago by tpartner.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.112 seconds
Donation Image