Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Multiple Choice

Multiple Choice 4 months 4 days 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: 4 months 4 days ago by flaviosantos. Reason: improve example
The administrator has disabled public write access.

Multiple Choice 4 months 3 days ago #108972

  • holch
  • holch's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2684
  • Thank you received: 326
  • Karma: 121
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 | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.
The following user(s) said Thank You: flaviosantos

Multiple Choice 4 months 3 days 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 4 months 3 days ago #109001

  • holch
  • holch's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2684
  • Thank you received: 326
  • Karma: 121
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 | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.
The following user(s) said Thank You: flaviosantos

Multiple Choice 4 months 3 days ago #109005

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

Multiple Choice 4 months 3 days 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 4 months 2 days ago #109026

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6338
  • Thank you received: 819
  • Karma: 243
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.
Last Edit: 4 months 2 days ago by DenisChenu.
The administrator has disabled public write access.
The following user(s) said Thank You: flaviosantos

Multiple Choice 4 months 2 days 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 4 months 2 days ago #109079

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.

Multiple Choice 4 months 1 day ago #109096

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6338
  • Thank you received: 819
  • Karma: 243
Mazi wrote:
Your example is total overkill, check Denis' example.
...

I'm i good mood ....

limesurvey.sondages.pro/632992/newtest/Y
The administrator has disabled public write access.
The following user(s) said Thank You: flaviosantos
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.254 seconds
Donation Image