Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Mutually Exclusive Answers to a multiple choice question using javascript

Mutually Exclusive Answers to a multiple choice question using javascript 1 Jahr 2 Monate her #100066

  • w0928
  • w0928s Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 33
  • Dank erhalten: 3
  • Karma: 1
This one is probably pretty easy for most folks here but I'm not very well-versed in javascript for LimeSurvey so I have no idea how it is done.

I have a multiple choice question and I would like to make it so that only 1 answer can be checked.

I know what you are thinking: use the exclusive answer option or use a radio-button style question.

The reason I do not want to use a radio button style question is because I want the user to be able to select "no answer" (nothing checked) and it seems as though radio buttons lock you in once a selection is made. I could add a "no answer" answer but I do not want to do this.

The reason I do not want to use the exclusive answer option is because you must uncheck your selection to re-enable the others before you can change your answer. I do not like this behavior. I'd like to allow the user to check on anything at any time and automatically have the other choices unchecked without having to uncheck the current selection first.

Appreciate any assistance. Thank you.

EDIT: Also, if anyone knows how to do this with an array(numbers)(checkbox style) question that would also be super helpful. :)
Letzte Änderung: 1 Jahr 2 Monate her von w0928. Begründung: edit
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Mutually Exclusive Answers to a multiple choice question using javascript 1 Jahr 2 Monate her #100069

  • w0928
  • w0928s Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 33
  • Dank erhalten: 3
  • Karma: 1
This is how I have it coded for a multiple choice question. I only have 2 answers: Yes (value of 1) and No (value of 2). There has got to be a better way of coding this, right?
<script type="text/javascript">
$(document).ready(function() {
$('#answer{SID}X{GID}X{QID}1').click(function (event) {
if ($( '#answer{SID}X{GID}X{QID}1' ).attr('checked') == true ) {
   $( '#answer{SID}X{GID}X{QID}2' ).attr('checked', false);
 
}
});
$('#answer{SID}X{GID}X{QID}2').click(function (event) {
if ($( '#answer{SID}X{GID}X{QID}2' ).attr('checked') == true ) {
   $( '#answer{SID}X{GID}X{QID}1' ).attr('checked', false);
}
});

EDIT: Also, it breaks my conditions for subsequent questions. I only show the next question if the answer to this one is yes. If they check yes it will show the next question. If they then click no, the yes will be unchecked but the next question still appears.
Letzte Änderung: 1 Jahr 2 Monate her von w0928.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Mutually Exclusive Answers to a multiple choice question using javascript 1 Jahr 2 Monate her #100077

  • w0928
  • w0928s Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 33
  • Dank erhalten: 3
  • Karma: 1
Anybody have a solution to this? I was able to get it working (conditions and all) on Chrome by changing the click functions to change functions and calling trigger('click') after setting the checked attribute to false but it doesn't work in IE at all.

So what I'd like to get working is to have 2 questions. The condition for question 2 is that the answer to question 1 is "Yes".

Basically...

Q1 Yes => change state from checked to not checked => yes is unchecked and question 2 is hidden
Q1 Yes => change state from not checked to checked => yes is checked, no is unchecked, and question 2 is shown
Q1 No => change state from checked to not checked => no is unchecked
Q1 No => change state from not checked to checked => no is checked, yes is unchecked, and question 2 is hidden
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.174 Sekunden
Donation Image