Disable radio buttons after selection

Mehr
2 Jahre 4 Wochen her - 2 Jahre 4 Wochen her #136748 von Deusdeorum
Deusdeorum erstellte das Thema Disable radio buttons after selection
So the subject title pretty much says what I'd like to do, after I select a radio button I want to lock all other options so that you cannot change your answer. I have been trying below javascript to do something like that but without success, im not sure where i am thinking wrong though..
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
		if($('#question{QID} input.radio:checked').length > 0) {
			radio.disabled = true;
		}
	});	
</script>
Letzte Änderung: 2 Jahre 4 Wochen her von Deusdeorum.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her #136753 von tpartner
tpartner antwortete auf das Thema: Disable radio buttons after selection
Try this:

<script type="text/javascript" charset="utf-8">		
	$(document).ready(function(){ 
		$('#question{QID} input.radio').on('click', function(e){
			$('#question{QID} input.radio').not(this).prop('disabled', true);
		});
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Folgende Benutzer bedankten sich: holch, Deusdeorum

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her #136754 von Deusdeorum
Deusdeorum antwortete auf das Thema: Disable radio buttons after selection

tpartner schrieb: Try this:

<script type="text/javascript" charset="utf-8">		
	$(document).ready(function(){ 
		$('#question{QID} input.radio').on('click', function(e){
			$('#question{QID} input.radio').not(this).prop('disabled', true);
		});
	});
</script>


Working like a charm, as always a very nice answer Tony, cheers!

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her #136761 von holch
holch antwortete auf das Thema: Disable radio buttons after selection
Works great in 2.5 (not tested in 2.06 yet).

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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her #136769 von holch
holch antwortete auf das Thema: Disable radio buttons after selection
Hmmm, I think I was judging too quick. I was using the same question for another issue to test something and I noticed that when you click on the answer option instead of the radio button, the radio buttons stay the same, but the response changes...

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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her #136770 von Deusdeorum
Deusdeorum antwortete auf das Thema: Disable radio buttons after selection

holch schrieb: Hmmm, I think I was judging too quick. I was using the same question for another issue to test something and I noticed that when you click on the answer option instead of the radio button, the radio buttons stay the same, but the response changes...


Not really sure what you mean, the javascript works for me even though you're clicking on the radio buttons or the corresponding text option. Version 2.06+ with a simple template

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her #136771 von tpartner
tpartner antwortete auf das Thema: Disable radio buttons after selection

Hmmm, I think I was judging too quick. I was using the same question for another issue to test something and I noticed that when you click on the answer option instead of the radio button, the radio buttons stay the same, but the response changes...

Oops, forgot about the labels - try this:

<script type="text/javascript" charset="utf-8">		
	$(document).ready(function(){ 
		$('#question{QID} input.radio').on('click', function(e){
			$('#question{QID} input.radio').not(this).prop('disabled', true);
			$('#question{QID} input.radio:checked').prop('disabled', false);
		});
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Folgende Benutzer bedankten sich: Ben_V

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her #136772 von holch
holch antwortete auf das Thema: Disable radio buttons after selection
Nope, still not working under 2.5.

I actually only noticed this, because in the next question I am referring to the response of this exact question via EM.

The radio button that was marked first stays marked. But when you click on the labels, they answer seems to change, as it changes the referred response in the next question.

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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her #136776 von tpartner
tpartner antwortete auf das Thema: Disable radio buttons after selection
Hmm, there seems to be a propagation of the checkconditions() function in 2.5. Try this:

<script type="text/javascript" charset="utf-8">		
	$('#question{QID} input.radio').on('click', function(e){
			$('#question{QID} input.radio').not(this).prop('disabled', true);
			$('#question{QID} input.radio:checked').prop('disabled', false).trigger('click');
		});
</script>

There may be a problem if returning to the page but my guess is if you are "locking" the radio questions after answering, you will not allow returning to the page.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her #136783 von holch
holch antwortete auf das Thema: Disable radio buttons after selection
Tested it, but now it does not do anything at all.

You can click through the answers just as if there wouldn't be any Javascript.

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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her #136786 von tpartner
tpartner antwortete auf das Thema: Disable radio buttons after selection
Holch, can you please supply a sample survey?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Wochen her - 2 Jahre 4 Wochen her #136818 von holch
holch antwortete auf das Thema: Disable radio buttons after selection
Hi Tpartner,

Please find my example attached.

I used the default template of 2.5 for testing (I am trying to force myself to use LS 2.5 for all new tests... ;) )


Dateianhang:

Dateiname: limesurvey...3472.lss
Dateigröße:15 KB

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
Anhang:
Letzte Änderung: 2 Jahre 4 Wochen her von holch.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 3 Wochen her - 2 Jahre 3 Wochen her #136891 von tpartner
tpartner antwortete auf das Thema: Disable radio buttons after selection
Okay, that was a typo on my part - forgot the $(document).ready() function.

Here is an extended version that:
1) Fixes the core event handler on the label div elements (that should never act on disabled radios)
2) Adds a class to all disabled answer rows so they can be styled as in the CSS example below
3) Handles the "Other" text input
3) Handles initial states in case of returning to the group

Script:
<script type="text/javascript" charset="utf-8">		
	$(document).ready(function(){ 
 
		// A function to disable all non-checked radios
		function handleDisableNonChecked(thisRadio) {
			var thisRow = $(thisRadio).closest('.answer-item');
			// Disable non-checked radios
			$('#question{QID} input.radio').not(thisRadio).prop('disabled', true);
			// Handle "Other" text input
			if($('input.text', thisRow).length == 0) {
				$('#question{QID} input.text').prop('disabled', true);
			}
			// Add a class to the disabled rows
			$('#question{QID} .answer-item').not(thisRow).addClass('disabled-row');
		}
 
		// Initial state (in case of returning to page
		if($('#question{QID} input.radio:checked').length > 0) {
			handleDisableNonChecked($('#question{QID} input.radio:checked'));
		}
 
		// Listener on the radios
		$('#question{QID} input.radio').on('click', function(e){
			handleDisableNonChecked(this);
		});
 
		// Fix the core event handler for the label div 
		$('#question{QID} .label-clickable').unbind('click').on('click', function(e){
			if(!$(this).parent().find('input.radio').is(':disabled')) {
				$(this).parent().find('input.radio').trigger('click');
			}
		});
	});
</script>

CSS:
.disabled-row .label-clickable{
    opacity: 0.45;
	cursor: not-allowed;
}

Modified test survey:

Dateianhang:

Dateiname: limesurvey...(v2).lss
Dateigröße:16 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Anhang:
Letzte Änderung: 2 Jahre 3 Wochen her von tpartner.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 3 Wochen her - 2 Jahre 3 Wochen her #136897 von Deusdeorum
Deusdeorum antwortete auf das Thema: Disable radio buttons after selection
Really nice answer Tony, your first solution worked up until I read

3) Handles initial states in case of returning to the group

So your latter solution is preferred and works great!
Letzte Änderung: 2 Jahre 3 Wochen her von Deusdeorum.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 3 Wochen her #136913 von holch
holch antwortete auf das Thema: Disable radio buttons after selection
I tried it without adding the CSS to the template and it seems to work fine. I assume the css only makes the lables less visible, right?

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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha