Using slider-value as default for next (numerical-input) question?

More
6 months 4 weeks ago - 6 months 4 weeks ago #221443 by irs_sept
Dear all, I guess I need some JavaScript help here...

Is it possible to have a normal numerical-input [v2] that is pre-filled with the result of a previous slider [v1_SQ001] from the same page?

> Whenever I move the slider, the value inside the numerical input will be replaced by the slider-value
> When I modify the numerical-input, the slider should not move

Thanks a lot!

EDIT:  LimeSurvey CloudVersion 3.27.19
Last edit: 6 months 4 weeks ago by irs_sept.

Please Log in to join the conversation.

More
6 months 3 weeks ago #221454 by tammo
Your are (partly) right, setting a default value does not work on the same page, but you can solve this using the slider value in the question text of a following question. When this question is on another page, setting the default value will work.

research.respondage.eu/index.php/317587?newtest=Y&lang=en (Limesurvey 3.x)

 


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl
Attachments:

Please Log in to join the conversation.

More
6 months 3 weeks ago #221456 by irs_sept
Thanks tammo!

I'm really confused why you can use the value from slider_SQ001 on the same page in the question text, you can also use this value for default-values on another page using JS, but you are not able to to this on the same page If you are familiar with JS, there is probably a good reason for this.

Nevertheless, THANKS for your example! Unfortunately, it's not what I'm looking for.

Please Log in to join the conversation.

More
6 months 3 weeks ago #221457 by tammo
I am not a programmer, so not familiar with JavaScript. I try to find workarounds and advice from people that know better... ;-)

Tammo


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl

Please Log in to join the conversation.

More
6 months 3 weeks ago #221458 by irs_sept
...100% exactly what I do as well. It's great to have this community here!

Please Log in to join the conversation.

More
6 months 3 weeks ago #221470 by tpartner
Place this script in the source of the numeric question. It will put a listener on the first slider found on the page and update the numeric input value as the slider is manipulated.
 
 
<script type="text/javascript" data-author="Tony Partner">	
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify elements
		var thisQuestion = $('#question{QID}');
		var thisInput = $('input:text', thisQuestion);
		var sliderQuestion = $('.numeric-multi:eq(0)');
		var sliderInput = $('input:text', sliderQuestion);
 
		$(sliderInput).on('slideEnabled',function(){ 
 
			// Listener on slider
			$(this).on('slide slideStop', function(event) {
				// Load the numeric input
				$(thisInput).val($(this).val());
			});
		});
    });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...1446.lss
File Size:35 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:

Please Log in to join the conversation.

More
6 months 3 weeks ago - 6 months 3 weeks ago #221472 by irs_sept
Thanks Tony! You are my hero!

EDIT: If someone is using this: You can change which slider is used in the following line:
var sliderQuestion= $('.numeric-multi:eq(0)');


eq(0) is the first slider, eq(1) the second and so on....
Last edit: 6 months 3 weeks ago by irs_sept.

Please Log in to join the conversation.

More
6 months 3 weeks ago - 6 months 3 weeks ago #221474 by tpartner

eq(0) is the first slider, eq(1) the second and so on

Close - that selector targets slider questions, not the actual sliders.

To target the sliders:

var sliderInput = $('.answer-item.slider-item:eq(0) input:text');

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 months 3 weeks ago by tpartner.
The following user(s) said Thank You: irs_sept

Please Log in to join the conversation.

More
6 months 3 weeks ago #221477 by irs_sept
Dear Tony,

may I ask you for one more thing?

Can you modify the code to just "transfer" values from the slider to the numerical input for values ">=0"?

I guess it's an easy fix. If it's complicated (and you are not bored) it's not that important.

Please Log in to join the conversation.

More
6 months 3 weeks ago #221482 by tpartner
This script in the source of the numeric question will load that question if the slider value is >= 0, otherwise it clears the numeric input. If you don't want it cleared, comment out the ELSE statement.
 
 
<script type="text/javascript" data-author="Tony Partner">	
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify elements
		var thisQuestion = $('#question{QID}');
		var thisInput = $('input:text', thisQuestion);
		var sliderInput = $('.answer-item.slider-item:eq(0) input:text');
 
		$(sliderInput).on('slideEnabled',function(){ 
 
			// Listener on slider
			$(this).on('slide slideStop', function(event) {
				// Load the numeric input if value is >= 0
				if($(this).val() >= 0) {
					$(thisInput).val($(this).val()).trigger('keyup');
				}
				else {
					$(thisInput).val('').trigger('keyup');
				}
			});
		});
    });
</script>

 Sample survey attached:

File Attachment:

File Name: limesurvey...6(1).lss
File Size:35 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:

Please Log in to join the conversation.

More
6 months 3 weeks ago #221483 by irs_sept
FANTASTIC!

Thanks a lot for your help!

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now