How to transform the two captured values coming from my range slider into form values

After a long search I've found a range slider I'd like to use for my form. I've found it in jQRangeSlider and allmost all works fine. But now I'd like to know how to get the chosen values and assign them to form values so I can retrieve them along with the other form values in my post part.
This is my script: It results in a range slider offering the user a time line between 8:00 hour and 17 Hour (European 24 hour format).

If tried to read the documentation but I could not make it work.

I'm not very good in javascript. Can someone please help me?

 
   <script>
    //<!--
	function TwoDigits(val){
		if (val < 10){
			 return "0" + val;
		}
		return val;
	}

	$("#slider").dateRangeSlider({
		bounds: {min: new Date(2018, 0, 1, 8), max: new Date(2018, 0, 1, 16, 59, 59)},
		defaultValues: {min: new Date(2018, 0, 1, 9), max: new Date(2018, 0, 1, 15)},
		formatter: function(value){
			var hours = value.getHours(),
				minutes = value.getMinutes();
			return TwoDigits(hours) + ":" + TwoDigits(minutes)+ " uur";
		}
	});
    //-->
    </script>

Open in new window

LVL 1
SteynskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
According to the Docs there's a ValuesChanged event so you probably want to hook into that, and set your form fields from there:

$("#slider").on("valuesChanged", function(e, data){
    $('#someFormField1').val(data.values.min);
    $('#someFormField2').val(data.values.max);
});

Open in new window

You also have the userValuesChanged event which may be preferable (code would be similar)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteynskAuthor Commented:
Thank your Chris for your quick comment.

But it does not generate a form value.
This is my goal and I don't know how to parse the values to the post process.

This is the script section :

   <script>
    //<!--
	function TwoDigits(val){
		if (val < 10){
			 return "0" + val;
		}
		return val;
	}

	$("#slider").dateRangeSlider({
		bounds: {min: new Date(2018, 0, 1, 8), max: new Date(2018, 0, 1, 16, 59, 59)},
		defaultValues: {min: new Date(2018, 0, 1, 9), max: new Date(2018, 0, 1, 15)},
		formatter: function(value){
			var hours = value.getHours(),
				minutes = value.getMinutes();
			return TwoDigits(hours) + ":" + TwoDigits(minutes)+ " uur";
		}
	});
	
	$("#slider").on("valuesChanged", function(e, data){
    $('min').val(data.values.min);
    $('max').val(data.values.max);
});
	
	
    //-->
    </script>

Open in new window

0
SteynskAuthor Commented:
I've found this jsfiddle example  http://jsfiddle.net/LJrYf/136/

But this one to generates only an alert and no form value
0
SteynskAuthor Commented:
I've tried :

<script>
    //<!--
      function TwoDigits(val){
            if (val < 10){
                   return "0" + val;
            }
            return val;
      }

      $("#slider").dateRangeSlider({
            bounds: {min: new Date(2018, 0, 1, 8), max: new Date(2018, 0, 1, 16, 59, 59)},
            defaultValues: {min: new Date(2018, 0, 1, 9), max: new Date(2018, 0, 1, 15)},
            formatter: function(value){
                  var hours = value.getHours(),
                        minutes = value.getMinutes();
                  return TwoDigits(hours) + ":" + TwoDigits(minutes)+ " uur";
            }
      });
      
      $("#slider").on("valuesChanged", function(e, data){
      document.getElementById("min").setAttribute('value',val(data.values.min));
      document.getElementById("max").setAttribute('value',val(data.values.max));

});
    //-->
</script>
0
SteynskAuthor Commented:
Thank you

I've got it this solves it.

I've had to create two hidden form input fields to make it work :

[code]<input type="hidden" id="beginTijd" name="beginTijd" />
<input type="hidden" id="eindTijd" name="eindTijd" />
<br>
<button id="btn" class="btn btn-warning" href="#">Submit</button>



<script>
    //<!--
      function TwoDigits(val){
            if (val < 10){
                   return "0" + val;
            }
            return val;
      }

      $("#slider").dateRangeSlider({
            bounds: {min: new Date(2018, 0, 1, 8), max: new Date(2018, 0, 1, 16, 59, 59)},
            defaultValues: {min: new Date(2018, 0, 1, 9), max: new Date(2018, 0, 1, 15)},
            formatter: function(value){
                  var hours = value.getHours(),
                        minutes = value.getMinutes();
                  return TwoDigits(hours) + ":" + TwoDigits(minutes)+ " uur";
            }
      });
      $('#btn').on('click', function(e) {
var dateValues = $("#slider").dateRangeSlider("values");
var minDate = dateValues.min.toString();
var maxDate = dateValues.max.toString();
$("#beginTijd").val( minDate );
$("#eindTijd").val( maxDate );

});[/code]
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.