Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Check which radio button has been checked?

Check which radio button has been checked? 3 years 1 month ago #63786

  • doodsonj
  • doodsonj's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 30
  • Thank you received: 2
  • Karma: 2
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.
The administrator has disabled public write access.

Re: Check which radio button has been checked? 3 years 1 month ago #63831

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6276
  • Thank you received: 801
  • Karma: 240
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
Last Edit: 3 years 1 month ago by DenisChenu.
The administrator has disabled public write access.
The following user(s) said Thank You: doodsonj

Re: Check which radio button has been checked? 3 years 4 weeks ago #64248

  • doodsonj
  • doodsonj's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 30
  • Thank you received: 2
  • Karma: 2
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: 3 years 4 weeks ago by doodsonj. Reason: clarification
The administrator has disabled public write access.

Re: Check which radio button has been checked? 3 years 4 weeks ago #64250

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6276
  • Thank you received: 801
  • Karma: 240
Hello,

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

An option aren't checked but selected ;).

:)
The administrator has disabled public write access.
The following user(s) said Thank You: doodsonj

Re: Check which radio button has been checked? 3 years 4 weeks ago #64253

  • doodsonj
  • doodsonj's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 30
  • Thank you received: 2
  • Karma: 2
Excellent - just what I was looking for. All sorted now.

Thanks Shnoulle.

J.
The administrator has disabled public write access.

Re: Check which radio button has been checked? 3 years 3 weeks ago #64392

  • simster
  • simster's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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';
  }
The administrator has disabled public write access.

Re: Check which radio button has been checked? 3 years 3 weeks ago #64410

  • simster
  • simster's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
Anyone have any thoughts as to why my code above isn't working as I had hoped?
The administrator has disabled public write access.

Re: Check which radio button has been checked? 3 years 3 weeks ago #64419

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4138
  • Thank you received: 767
  • Karma: 348
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Check which radio button has been checked? 3 years 3 weeks ago #64420

  • simster
  • simster's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
The survey is question by question so it is not on the same page. I tried the code you gave and no luck.
The administrator has disabled public write access.

Re: Check which radio button has been checked? 3 years 3 weeks ago #64424

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4138
  • Thank you received: 767
  • Karma: 348
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.244 seconds
Donation Image