How to access selected answers / answer options on end page with jquery?

More
2 months 2 weeks ago #197828 by horsti2010
Hi everyone,

I have a question that might be simple and easy to answer. At the final page of my survey, the "Thank you for participating" page, I need to access the responses of some of the previously answered questions with jquery.

For example: I have a survey with just one question (question code: Q1, ID 155) which is a single answer option. I have three answer options for this question = radio buttons: "Answer1" (code: A1), "Answer2" (code: A2) and "Answer 3" (code: A3) and only one can be selected. How can I get the value of the selected answer option for this question on the final page? Let's assume I would like to simply "alert" with jquery the selected answer, e. g. "Answer 1"?

The reason why I need this is that I have a little script that is supposed to pass the selected answer to an external database. I tried some variations of the following, but it just show a blank popup without the value or "undefined":
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){	
		alert($('#question{155} input[type="radio"]:checked').val());
	});
</script>

Any help is appreciated :-)

Please Log in to join the conversation.

LimeSurvey Partners
More
2 months 2 weeks ago #197845 by DenisChenu
Time to read manual.limesurvey.org/Expression_Manager
…

{Q1.NAOK} give you the code of selected answer

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.

Please Log in to join the conversation.

More
2 months 2 weeks ago #197846 by Joffm
Hi, with my limited knowledge of javascript here is a variation that gives you the result that you like to have.

Use Expression Manager/Script.
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){	
		var x='{QCode}';
		alert(x);
	});
</script>


If you use numerical codes the quotes around the question code are not necessary.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

More
2 months 2 weeks ago - 2 months 2 weeks ago #197889 by horsti2010
Hey guys,

Thanks for the answers! I actually read the manual, but was not able to figure out how to access it precisely. I will try your hints and will give feedback on how it went.

Have a good week-end!


###Update###
It works - in the end it is so simple, but yet I tried it for a couple of hours... Guys, you helped me a lot!!!
For all who are interested in a working code script, here it is:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){	
		var x='{Q1}';
		var y='{Q1.shown}';
		alert(x + y);
	});
</script>

In this example, I have question Q1 which is a simple radio option list (single choice). var x='{Q1}' saves the question code (which is Q1) in variable x and var y='{Q1.shown}' saves the selected answer option in variable y. With that, the transfers to Javascript/Jquery is successful and you can use x and y for any follow-up manipulations at the survey end :-)
Last edit: 2 months 2 weeks ago by horsti2010. Reason: Updated my answer

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now