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?
 
Chris StanyonConnect With a Mentor Commented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.