- Posts: 11
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How to access selected answers / answer options on end page with jquery?
- horsti2010
- Topic Author
- Offline
- New Member
Less
More
3 years 11 months ago #197828
by horsti2010
How to access selected answers / answer options on end page with jquery? was created 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":
Any help is appreciated
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":
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ alert($('#question{155} input[type="radio"]:checked').val()); }); </script>
Any help is appreciated
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13935
- Thank you received: 2551
3 years 11 months ago #197845
by DenisChenu
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.
Replied by DenisChenu on topic How to access selected answers / answer options on end page with jquery?
Time to read
manual.limesurvey.org/Expression_Manager
…
{Q1.NAOK} give you the code of selected answer
…
{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.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12789
- Thank you received: 3940
3 years 11 months ago #197846
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic How to access selected answers / answer options on end page with jquery?
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.
If you use numerical codes the quotes around the question code are not necessary.
Joffm
Use Expression Manager/Script.
Code:
<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
The following user(s) said Thank You: DenisChenu
The topic has been locked.
- horsti2010
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
3 years 11 months ago - 3 years 11 months ago #197889
by horsti2010
Replied by horsti2010 on topic How to access selected answers / answer options on end page with jquery?
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:
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
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:
Code:
<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: 3 years 11 months ago by horsti2010. Reason: Updated my answer
The topic has been locked.