Welcome, Guest
Username: Password:

TOPIC: problems with javascript

problems with javascript 4 years 10 months ago #62331

  • mattias
  • mattias's Avatar
  • Offline
  • Senior Lime
  • Posts: 79
  • Karma: 1
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
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62335

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5785
  • Thank you received: 1260
  • Karma: 514
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.
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62336

  • mattias
  • mattias's Avatar
  • Offline
  • Senior Lime
  • Posts: 79
  • Karma: 1
tpartner both questions are like:

Q1 = radio
Q2 = radio

Greetings, Thanks
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62337

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5785
  • Thank you received: 1260
  • Karma: 514
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.
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62340

  • mattias
  • mattias's Avatar
  • Offline
  • Senior Lime
  • Posts: 79
  • Karma: 1
friend sends you a snapshot, I hope you understand better idea.

Greetings, Thanks


Last Edit: 4 years 10 months ago by mattias.
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62397

  • mattias
  • mattias's Avatar
  • Offline
  • Senior Lime
  • Posts: 79
  • Karma: 1
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
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62408

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5785
  • Thank you received: 1260
  • Karma: 514
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 administrator has disabled public write access.
The following user(s) said Thank You: mattias

problems with javascript 4 years 10 months ago #62416

  • mattias
  • mattias's Avatar
  • Offline
  • Senior Lime
  • Posts: 79
  • Karma: 1
thank you very much my friend, it worked very well

thanks for your time and dedication, greetings from Chile.
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62419

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5785
  • Thank you received: 1260
  • Karma: 514
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.
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62444

  • mattias
  • mattias's Avatar
  • Offline
  • Senior Lime
  • Posts: 79
  • Karma: 1
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
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62449

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5785
  • Thank you received: 1260
  • Karma: 514
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 administrator has disabled public write access.
The following user(s) said Thank You: mattias

problems with javascript 4 years 10 months ago #62452

  • mattias
  • mattias's Avatar
  • Offline
  • Senior Lime
  • Posts: 79
  • Karma: 1
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
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62472

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5785
  • Thank you received: 1260
  • Karma: 514
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.
The administrator has disabled public write access.

problems with javascript 4 years 10 months ago #62488

  • mattias
  • mattias's Avatar
  • Offline
  • Senior Lime
  • Posts: 79
  • Karma: 1
thanks friend solved the problem with what I stated.

regards
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.413 seconds