Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Multiple Choice

Multiple Choice 2 years 6 months ago #108969

Hi,

I'm from Brazil and new to LimeSurvey world, and today I started learning the basics.

But the multiple choice stopped me a little.

i.e.: the question that I have, which uses Multiple choice - let users choose all if the user wish.

But I would like to disable some choices for example when a user clicks and check DAY - disable NIGHT, when check SUN disable Moon

Thanks in advance for the attention and help.

And sorry about my English I'm still learning.
Last Edit: 2 years 6 months ago by flaviosantos. Reason: improve example
The administrator has disabled public write access.

Multiple Choice 2 years 6 months ago #108972

  • holch
  • holch's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5425
  • Thank you received: 807
  • Karma: 239
As your example always has just 2 choices, I would go for a normal list (Radio buttons instead of check boxes) and not for multiple choice.

But I assume that your example is probably a little more complicated.

If you have like 4 items and if you chose item 1, item 2 should be disabled but item 3 and for should be still enabled, this would be a lot more complicated to do. You probably would need some custom javascript to do this.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | [url=https://manual.limesurvey.org/Workarounds[/url]

If you found this answer helpful and it saved you some time please consider a [url=https://donate.limesurvey.org[/url] to the...
The administrator has disabled public write access.
The following user(s) said Thank You: flaviosantos

Multiple Choice 2 years 6 months ago #108994

Thanks!

I will look for javascript then,

Do you where to code javascript into limesurvey?
The administrator has disabled public write access.

Multiple Choice 2 years 6 months ago #109001

  • holch
  • holch's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5425
  • Thank you received: 807
  • Karma: 239
You can simply include the javascript into the text box for the question (switch off the WYSIWYG editor), but you will need to switch off the XSS filter. In the workaround section of the manual there is a whole article on how to use Javascript in Limesurvey, just have a look.

Um abraço desde São Paulo!
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | [url=https://manual.limesurvey.org/Workarounds[/url]

If you found this answer helpful and it saved you some time please consider a [url=https://donate.limesurvey.org[/url] to the...
The administrator has disabled public write access.
The following user(s) said Thank You: flaviosantos

Multiple Choice 2 years 6 months ago #109005

Thanks!
Obrigado!
The administrator has disabled public write access.

Multiple Choice 2 years 6 months ago #109007

This script below seems to have the features that I'm looking for, but how do I load it for checkboxes, I know that the first part between <head></head> goes into the question source code

But the code for subquestions I do not know how to apply and how to pass this code they way LimeSurvey understand.
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
 
<script type="text/javascript">
<!--
onload = function () {
	var e, i = 0;
	while (e = document.forms[0].elements[['fie', 'foe', 'fum'][i++]]) {
		e.disabled = true;
	}
}
// -->
</script>
 
<style type="text/css">
<!-- 
fieldset {padding:1ex; width:10em}
label {display:block; text-align:left}
input {margin-right:1ex}
button {display:block; margin:1ex auto}
-->
</style>
 
</head>
<body>
<form action="some-script.pl">
<fieldset>
<legend>Giant Says</legend>
<label><input name="fee" onClick="this.form.fie.disabled = !this.checked" type="checkbox">Fee</label>
<label><input name="fie" onClick="this.form.foe.disabled = !this.checked" type="checkbox">Fie</label>
<label><input name="foe" onClick="this.form.fum.disabled = !this.checked" type="checkbox">Foe</label>
<label><input name="fum" type="checkbox">Fum</label>
<button name="go" type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>
The administrator has disabled public write access.

Multiple Choice 2 years 6 months ago #109026

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9572
  • Thank you received: 1374
  • Karma: 390
LimeSurvey include jquery : api.jquery.com/

Then use jquery.
$("input[name='foe']").click(function(){
var ischecked=$(this).prop('checked');
if(ischecked){
$("input[name='fie']").prop('checked',false).prop('disabled',true);
}else{
$("input[name='fie']").prop('disabled',false);
}
}
Or somethink like that.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (use private message).
Last Edit: 2 years 6 months ago by DenisChenu.
The administrator has disabled public write access.
The following user(s) said Thank You: flaviosantos

Multiple Choice 2 years 6 months ago #109076

I tried this code, but also nothing happens:
<script type='text/javascript'>
 
var form = document.getElementById("limesurvey");
form.onclick = delegateFormClick;
 
addChangeHandlers(form);
 
function addChangeHandlers(form)
{
   for(var i=0;i<form.elements.length;i++)
   {
       var element = form.elements[i];
       if(element.tagName === "INPUT" && element.type === "checkbox")
       {
           if(!element.onchange)
           {
               element.onchange = checkBoxChanged;   
           }
       }
   }  
}
 
function delegateFormClick(evt)
{
    var target;
    if(!evt)
    {
        //Microsoft DOM
        target = window.event.srcElement;
    }else if(evt)
    {
        //w3c DOM 
        target = evt.target;
    }
    if(target.nodeType === 1 && target.tagName === "INPUT" && target.type === "checkbox")
    {
        if(target.checked)
        {
            disableCheckBoxes(target.id, document.getElementById("limesurvey"));
        }else if(!target.checked)
        {
            enableCheckBoxes(document.getElementById("limesurvey"));
        }  
    }
}
 
function checkBoxChanged()
{
    if(this.checked)
    {
       disableCheckBoxes(this.id, document.getElementById("limesurvey")); 
    }else if(!this.checked)
    {
        enableCheckBoxes(document.getElementById("limesurvey"));  
    }
}
 
function disableCheckBoxes(id, form)
{
    var blacklist = [];
    if(id)
    {
        switch(id)
        {
            case "answer119117X4X138s01":
            blacklist = ["answer119117X4X138s07", "answer119117X4X138s06"];
            break;
            case "answer119117X4X138s07":
            blacklist = ["answer119117X4X138s01", "answer119117X4X138s04"];
            break;
            case "answer119117X4X138s03":
            blacklist = ["answer119117X4X138s010", "answer119117X4X138s09"];
            break;
        }   
    }else
    {
        throw new Error("id is needed to hard-wire input blacklist");   
    }
    for(var i=0;i<blacklist.length;i++)
    {
        var element = document.getElementById(blacklist[i]);
        if(element && element.nodeType === 1)
        {
            //check for element
            if(element.tagName === "INPUT" && element.type === "checkbox" && !element.checked)
            {
                element.disabled = "disabled";
            }
        }else if(!element || element.nodeType !== 1)
        {
            throw new Error("input blacklist item does not exist or is not an element");
        }
    }   
}
 
function enableCheckBoxes(form)
{
    for(var i=0;i<form.elements.length;i++)
    {
        var element = form.elements[i];
        if(element.tagName === "INPUT" && element.type === "checkbox" && !element.checked)
        {
            element.disabled = "";
        }
    }   
}
</script>
The administrator has disabled public write access.

Multiple Choice 2 years 6 months ago #109079

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6028
  • Thank you received: 373
  • Karma: 260
Your example is total overkill, check Denis' example.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
The administrator has disabled public write access.

Multiple Choice 2 years 6 months ago #109096

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9572
  • Thank you received: 1374
  • Karma: 390
Mazi wrote:
Your example is total overkill, check Denis' example.
...

I'm i good mood ....

limesurvey.sondages.pro/632992/newtest/Y
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (use private message).
The administrator has disabled public write access.
The following user(s) said Thank You: flaviosantos

Multiple Choice 2 years 6 months ago #109153

Thanks Denis

By the very beautiful template
The administrator has disabled public write access.
Time to create page: 0.256 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form