Hiding a checkbox in a multiple-opt question type (0 viewing)
|
|
|
TOPIC: Hiding a checkbox in a multiple-opt question type
|
dfewl
Fresh Lemon
Posts: 11
|
|
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
|
|
|
The administrator has disabled public write access.
|
|
|
|
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
|
|
|
Cheers,
Tony
|
|
|
The administrator has disabled public write access.
|
Mazi
Moderator Lime
Posts: 6876
|
|
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
|
|
|
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.
|
|
|
|
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
|
|
|
Cheers,
Tony
|
|
|
The administrator has disabled public write access.
|
dfewl
Fresh Lemon
Posts: 11
|
|
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
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Hiding a checkbox in a multiple-opt question type 6 Months, 3 Weeks ago
|
Karma: 34
|
|
You're welcome.
|
|
|
|
Logged
|
|
|
Cheers,
Tony
|
|
|
The administrator has disabled public write access.
|
Mazi
Moderator Lime
Posts: 6876
|
|
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
|
|
|
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.
|
|
|
|
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
|
|
|
The administrator has disabled public write access.
|
|
|
|
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
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
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
|
|
|
The administrator has disabled public write access.
|
|
|
|
|