Check out the LimeSurvey source code on GitHub!

problems with javascript

More
5 years 8 months ago #62331 by mattias01
you can take a value from a previous question and display it as radio type text according to a next question I was reading you can do with javascript, but the implementation of the code is not very clear, could help appreciated.

the example works as follows:

1 .- Question 1
option 1
option 2
option 3
2 .- Question 2
The value of option 1 is: (option1)

Thanks in advance

Please Log in to join the conversation.

More
5 years 8 months ago #62335 by tpartner
What are the 2 question types?

Q1 = Radio?
Q2 = Short text?

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 8 months ago #62336 by mattias01
tpartner both questions are like:

Q1 = radio
Q2 = radio

Greetings, Thanks

Please Log in to join the conversation.

More
5 years 8 months ago #62337 by tpartner
Okay, but I'm not sure what you are trying to achieve. Can you supply a small sample survey and maybe screenshots?

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 8 months ago - 5 years 8 months ago #62340 by mattias01
friend sends you a snapshot, I hope you understand better idea.

Greetings, Thanks


Attachments:
Last Edit: 5 years 8 months ago by mattias01.

Please Log in to join the conversation.

More
5 years 8 months ago #62397 by mattias01
tpartner

I want to accomplish is similar to this example, but you must load the value in the same section of the survey.

www.partnersinc.biz/surveys//index.php?s...52&newtest=Y&lang=en

I hope I have been a little clearer.

Greetings, Thanks

Please Log in to join the conversation.

More
5 years 8 months ago #62408 by tpartner
Oh, I see, something like {INSERTANS} but with both questions on the same page.

Set up your survey to use JavaScript .

Wrap the text in Q2 that is to be replaced in a span with a class "pipedText". So the source of that question should look something like:
The answer from a previous question on this page is: "<span class="pipedText">text to be replaced</span>".

Add the following script to the source of one of the questions. Replace "QQ" with the Q1 question ID .
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		var qID = QQ; 
 
		$('#question'+qID+' input.radio').click(function(){
			$('.pipedText').text($(this).siblings('label').text());
		});
 
	});
 
</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: mattias01

Please Log in to join the conversation.

More
5 years 8 months ago #62416 by mattias01
thank you very much my friend, it worked very well

thanks for your time and dedication, greetings from Chile.

Please Log in to join the conversation.

More
5 years 8 months ago #62419 by tpartner
No problem and regards from Ottawa, Canada.

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 8 months ago #62444 by mattias01
friend

I have one last question on this topic, in case you want to do the same but one section of the survey would have to modify the QQ
eg: 1111X22X3 because this modification and do not work for me.

regards

Please Log in to join the conversation.

More
5 years 8 months ago #62449 by tpartner
If you want to do it to more questions on the same page, use something like the following.

The answer of question ID 11 will be piped into the text of questionID 22 and the answer of question ID 33 will be piped into the text of questionID 44.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		pipeText(11, 22);
		pipeText(33, 44); 
 
		function pipeText(q1ID, q2ID){
			$('#question'+q1ID+' input.radio').click(function(){
				$('#question'+q2ID+' .pipedText').text($(this).siblings('label').text());
			});
		}
 
	});
 
</script>


Add as many function calls as necessary:
		pipeText(11, 22);
		pipeText(33, 44);
		pipeText(55, 66);
		pipeText(77, 88);

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: mattias01

Please Log in to join the conversation.

More
5 years 8 months ago #62452 by mattias01
but my question is to work with different pages eg:

Page1

Q1 = Question 1
question 2

Q2 = the value of question 1 is: example (Question1)

page 2

Q3 = the value of question 1 is: example (Question 1)

I hope I have been more clear.

regards

Please Log in to join the conversation.

More
5 years 8 months ago #62472 by tpartner
For questions on subsequent pages you don't need JavaScript. You can use {INSERTANS} - docs.limesurvey.org/Adding+a+question&hi...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 8 months ago #62488 by mattias01
thanks friend solved the problem with what I stated.

regards

Please Log in to join the conversation.

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