- Posts: 72
- Thank you received: 17
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Disable radio buttons after selection
- Deusdeorum
- Topic Author
- Offline
- Senior Member
Less
More
7 years 10 months ago - 7 years 10 months ago #136748
by Deusdeorum
Disable radio buttons after selection was created by Deusdeorum
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..
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { if($('#question{QID} input.radio:checked').length > 0) { radio.disabled = true; } }); </script>
Last edit: 7 years 10 months ago by Deusdeorum.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
7 years 10 months ago #136753
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Disable radio buttons after selection
Try this:
Code:
<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.
The following user(s) said Thank You: holch, Deusdeorum
The topic has been locked.
- Deusdeorum
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 72
- Thank you received: 17
7 years 10 months ago #136754
by Deusdeorum
Working like a charm, as always a very nice answer Tony, cheers!
Replied by Deusdeorum on topic Disable radio buttons after selection
tpartner wrote: Try this:
Code:<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!
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11758
- Thank you received: 2753
7 years 10 months ago #136761
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Disable radio buttons after selection
Works great in 2.5 (not tested in 2.06 yet).
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11758
- Thank you received: 2753
7 years 10 months ago #136769
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic 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 answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- Deusdeorum
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 72
- Thank you received: 17
7 years 10 months ago #136770
by Deusdeorum
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
Replied by Deusdeorum on topic Disable radio buttons after selection
holch wrote: 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
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
7 years 10 months ago #136771
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Disable radio buttons after selection
Oops, forgot about the labels - try this: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...
Code:
<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.
The following user(s) said Thank You: Ben_V
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11758
- Thank you received: 2753
7 years 10 months ago #136772
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic 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 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 answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
7 years 10 months ago #136776
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Disable radio buttons after selection
Hmm, there seems to be a propagation of the checkconditions() function in 2.5. Try this:
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.
Code:
<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.
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11758
- Thank you received: 2753
7 years 10 months ago #136783
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic 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.
You can click through the answers just as if there wouldn't be any Javascript.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
7 years 10 months ago #136786
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic 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.
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11758
- Thank you received: 2753
7 years 10 months ago - 7 years 10 months ago #136818
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic 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... )
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... )
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Attachments:
Last edit: 7 years 10 months ago by holch.
The topic has been locked.