Check out the LimeSurvey source code on GitHub!

Check which radio button has been checked?

More
5 years 6 months ago #63786 by doodsonj_duplicate
Hi Team,

Does anybody know whether this is a quick bit of code which will return which value of specific radio button has been checked (i.e. whether 'option1', 'option2', or 'option3' has been checked?).

Alternatively, if there a quick bit of code which will return whether a specific value of a radio button has been checked (i.e. if option1 is checked, return true)

The code would be run when a specific button is clicked on a page, and would refer to a radio button option on the same page.

No worries if it is complicated, but thought I'd ask if there was a quick few lines of code.

Thanks, J.

Please Log in to join the conversation.

More
5 years 6 months ago - 5 years 6 months ago #63831 by DenisChenu
Without work on it.

You can have a look to jquery doc.
api.jquery.com/checked-selector/

The code in this page, with little adaptation for question 42
<script>
$("#question42 input.radio").click(function() {
  $("#log").html( $(":checked").val() + " is checked!" );
});
</script>
After you can do test lime
if ($("#question42 input.radio:checked").val()=="value01"){
//
}
I think

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).
Last Edit: 5 years 6 months ago by DenisChenu.
The following user(s) said Thank You: doodsonj_duplicate

Please Log in to join the conversation.

More
5 years 6 months ago - 5 years 6 months ago #64248 by doodsonj_duplicate
Thanks Schnoulle. Sorry about the time it has taken for me to respond. This worked fine, and I now understand how the jscript references the radio button and text input fields.

One final quick question (I've not been able to find an answer by looking at the JQuery website to which you linked):

I couldn't work out how to adapt the code to return which item in a list-dropbox item had been selected (either the number of the item in the list, or the text of the item in the list).
if ($("#question42 input.list-dropdown:checked").val()=="value01"){
//
}

If anybody knows whether list is reference in any other way (I've tried 'radio' as I though listbox might be a type of radio, but it didn't seem to work).

Any ideas or knowledge about would be grateful.

Thanks again, as ever.

J.
Last Edit: 5 years 6 months ago by doodsonj_duplicate. Reason: clarification

Please Log in to join the conversation.

More
5 years 6 months ago #64250 by DenisChenu
Hello,

something with selected i think
api.jquery.com/selected-selector/

An option aren't checked but selected ;).

:)

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).
The following user(s) said Thank You: doodsonj_duplicate

Please Log in to join the conversation.

More
5 years 6 months ago #64253 by doodsonj_duplicate
Excellent - just what I was looking for. All sorted now.

Thanks Shnoulle.

J.

Please Log in to join the conversation.

More
5 years 6 months ago #64392 by simster
Not to hijack this thread but I'm trying to accomplish the same thing only looking for the answer to a previous question (array-flexible-row) with radio buttons. Columns are A1-A5 with Rows A-E.

Code I am trying:
if ($("#answer42272X1X25A input.radio:checked").val()=="A1")
  {
    r1 = '1';
  }

Please Log in to join the conversation.

More
5 years 6 months ago #64410 by simster
Anyone have any thoughts as to why my code above isn't working as I had hoped?

Please Log in to join the conversation.

More
5 years 6 months ago #64419 by tpartner
The rows of an array type question are tbody elements with IDs like #javatbdSSXGGXQQAA.

So to check for the checked value in a given row, try something like this (assuming the question is on the same page):
if ($('#javatbd77592X298X9535A input.radio:checked').val() == "A1") {
		var r1 = '1';
	}

Cheers,
Tony Partner

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

Please Log in to join the conversation.

More
5 years 6 months ago #64420 by simster
The survey is question by question so it is not on the same page. I tried the code you gave and no luck.

Please Log in to join the conversation.

More
5 years 6 months ago #64424 by tpartner
If questions are on separate pages, you will need to use {INSERTANS} to recover the checked value - docs.limesurvey.org/Adding+a+question&st...rom_previous_answers

Cheers,
Tony Partner

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

Please Log in to join the conversation.

More
5 years 6 months ago #64427 by simster
so an {INSERTANS} from a radio button will be true or false or will it carry the value from the column?? Sorry for so many questions but I do appreciate your help.

Please Log in to join the conversation.

More
5 years 6 months ago #64430 by simster
I figured it out (it carries the value of the scale (1-5). Thanks for the point in the right direction.

Please Log in to join the conversation.

More
5 years 6 months ago #64613 by TMSWhite
I've started a wiki page to try to address some of these questions about how to access and manipulate values using JQuery (although I was more focused on clearing values than on retrieving a particular one).

Perhaps the team could consolidate these sort of recommendations in one place, grouped by question type, so that we can more easily point users to quick answers (or more easily link to it if such a page already exists)?

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form