LimeSurvey Forums
Welcome, Guest
Please Login or Register.    Lost Password?
Hiding a checkbox in a multiple-opt question type
(0 viewing) 
Go to bottom
  • Page:
  • << Start < Prev 1 2 Next > End >>
TOPIC: Hiding a checkbox in a multiple-opt question type
#37509
dfewl
Fresh Lemon
Posts: 11
graphgraph
User Offline Click here to see the profile of this user
Hiding a checkbox in a multiple-opt question type 6 Months, 4 Weeks ago Karma: 0
I saw the code on how to hide the comment box in multiple-opt with comments question types, but can somebody tell me how to hide a particular option in a regular multiple-opt question type?
 
Logged Logged
  The administrator has disabled public write access.
#37523
tpartner
LimeSurvey Team
Posts: 1051
graphgraph
User Offline Click here to see the profile of this user
Re:Hiding a checkbox in a multiple-opt question type 6 Months, 4 Weeks ago Karma: 34
Set up your survey to use JavaScript and place the following in the source of the multi-options question. Replace "QQ" with the multi-options question ID and "NN" with the option number you want to hide.
Code:

<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

function hideOption(qID, optNum) {
var index = optNum - 1;
$('#question' + qID + ' td.answer li:eq(' + index + ')').hide();
}

hideOption(QQ, NN)
});

</script>

 
Logged Logged
 
Cheers,
Tony
  The administrator has disabled public write access.
#37534
Mazi
Moderator Lime
Posts: 6876
graph
User Offline Click here to see the profile of this user
Re:Hiding a checkbox in a multiple-opt question type 6 Months, 4 Weeks ago Karma: 93
Tony,
can this also be done by a line of CSS in template.css? Might be an easier solution than using JS?!
 
Logged Logged
 
Best regards,
Mazi
______________________
Need help? I can: set up Limesurvey for you / create your survey / implement additional features / design your template / offer premium support --> Contact
  The administrator has disabled public write access.
#37554
tpartner
LimeSurvey Team
Posts: 1051
graphgraph
User Offline Click here to see the profile of this user
Re:Hiding a checkbox in a multiple-opt question type 6 Months, 4 Weeks ago Karma: 34
Yes, you could do it with CSS - each list item has a unique ID. However I just assumed that dfewl was looking for the capability of dynamically hiding an option. That is, if something happens, then hide the option.

So the code would really be something like:
Code:

<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

function hideOption(qID, optNum) {
var index = optNum - 1;
$('#question' + qID + ' td.answer li:eq(' + index + ')').hide();
}

if (somecondition) {
hideOption(QQ, NN);
}
});

</script>

 
Logged Logged
 
Cheers,
Tony
  The administrator has disabled public write access.
#37637
dfewl
Fresh Lemon
Posts: 11
graphgraph
User Offline Click here to see the profile of this user
Re:Hiding a checkbox in a multiple-opt question type 6 Months, 3 Weeks ago Karma: 0
Thanks everybody for your responses. This worked great for what I needed, and the re-usability of this code is a nice bonus. I'm beginning to have a better understanding of the different CSS elements.
 
Logged Logged
  The administrator has disabled public write access.
#37643
tpartner
LimeSurvey Team
Posts: 1051
graphgraph
User Offline Click here to see the profile of this user
Re:Hiding a checkbox in a multiple-opt question type 6 Months, 3 Weeks ago Karma: 34
You're welcome.
 
Logged Logged
 
Cheers,
Tony
  The administrator has disabled public write access.
#37646
Mazi
Moderator Lime
Posts: 6876
graph
User Offline Click here to see the profile of this user
Re:Hiding a checkbox in a multiple-opt question type 6 Months, 3 Weeks ago Karma: 93
You're welcome! If our hints have been helpful and you enjoy limesurvey please consider a donation to the team . We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.
 
Logged Logged
 
Best regards,
Mazi
______________________
Need help? I can: set up Limesurvey for you / create your survey / implement additional features / design your template / offer premium support --> Contact
  The administrator has disabled public write access.
#43879
lsexton
Gold Donator
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
Re:Hiding a checkbox in a multiple-opt question type 3 Months ago Karma: 0
Found this thread very useful thanks!

I have this code working using the clear_logo template, however when I change to the limespired template, the code doesn't seem to work. Is there something I am missing here? Here is the code, and the two alerts do display when I test it, but the multi-option #1 doesn't disappear:

<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

function hideOption(qID, optNum) {
var index = optNum - 1
$('#question' + qID + ' td.answer li:eq(' + index + ')').hide();
}
alert('It gets here also!');

hideOption(3200, 1);
alert('It gets here too!');
});

</script>

Thanks for the help in advance!
 
Logged Logged
  The administrator has disabled public write access.
#43892
Shnoulle
Moderator Lime
Posts: 1079
graphgraph
User Offline Click here to see the profile of this user
Re:Hiding a checkbox in a multiple-opt question type 3 Months ago Karma: 23
I don't look a lot, but i think you can remove the td.

Code:

<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

function hideOption(qID, optNum) {
var index = optNum - 1
$('#question' + qID + '.answer li:eq(' + index + ')').hide();
}
alert('It gets here also!');

hideOption(3200, 1);
alert('It gets here too!');
});

</script>

 
Logged Logged
 
  The administrator has disabled public write access.
#43902
lsexton
Gold Donator
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
Re:Hiding a checkbox in a multiple-opt question type 3 Months ago Karma: 0
Thanks for the quick reply, but no luck with that. In fact removing the td makes it no longer work with the clear_logo template, and still not working within limespired.

If it helps, I'm using v 1.86
Cheers,
Luke
 
Logged Logged
  The administrator has disabled public write access.
Go to top
  • Page:
  • << Start < Prev 1 2 Next > End >>
Donation Image