Multiple Choice

More
3 years 3 months ago - 3 years 3 months ago #108969 by flaviosantos
flaviosantos created the topic: Multiple Choice
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: 3 years 3 months ago by flaviosantos. Reason: improve example

Please Log in to join the conversation.

More
3 years 3 months ago #108972 by holch
holch replied the topic: Multiple Choice
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.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds
The following user(s) said Thank You: flaviosantos

Please Log in to join the conversation.

More
3 years 3 months ago #108994 by flaviosantos
flaviosantos replied the topic: Multiple Choice
Thanks!

I will look for javascript then,

Do you where to code javascript into limesurvey?

Please Log in to join the conversation.

More
3 years 3 months ago #109001 by holch
holch replied the topic: Multiple Choice
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!

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds
The following user(s) said Thank You: flaviosantos

Please Log in to join the conversation.

More
3 years 3 months ago #109005 by flaviosantos
flaviosantos replied the topic: Multiple Choice
Thanks!
Obrigado!

Please Log in to join the conversation.

More
3 years 3 months ago #109007 by flaviosantos
flaviosantos replied the topic: Multiple Choice
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>

Please Log in to join the conversation.

More
3 years 2 months ago - 3 years 2 months ago #109026 by DenisChenu
DenisChenu replied the topic: Multiple Choice
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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 3 years 2 months ago by DenisChenu.
The following user(s) said Thank You: flaviosantos

Please Log in to join the conversation.

More
3 years 2 months ago #109076 by flaviosantos
flaviosantos replied the topic: Multiple Choice
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>

Please Log in to join the conversation.

More
3 years 2 months ago #109079 by Mazi
Mazi replied the topic: Multiple Choice
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'"

Please Log in to join the conversation.

More
3 years 2 months ago #109096 by DenisChenu
DenisChenu replied the topic: Multiple Choice

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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: flaviosantos

Please Log in to join the conversation.

More
3 years 2 months ago #109153 by flaviosantos
flaviosantos replied the topic: Multiple Choice
Thanks Denis

By the very beautiful template

Please Log in to join the conversation.

Did you already participate in our customer survey?

Don't miss your chance for great prices.

Please click here to participate:

Start now

Start now!

Just create your account and start using Limesurvey today.

Register now