Solved

How to extract user defined date range values using JQRangeSlider?

Posted on 2014-07-29
3
1,004 Views
Last Modified: 2014-08-05
I am using the JQRangeSlider's dateRangeSlider to allow a user to select a date range.

I need to record the values of the dateRangeSlider for use in my HTML form.

The dateRangeSlider works perfectly.

//BUILD RANGE SLIDER
$("#slider").dateRangeSlider(
	{					
		bounds: {
			min: new Date(2013, 0, 1), 
			max: new Date(2014, 6, 29)
		},
		defaultValues: {
			min: new Date(2014, 3, 29), 
			max: new Date(2014, 6, 29)
		},
		symmetricPositionning: true,
		range: {min: 0},
		formatter:function(val){
			var month = val.getMonth() + 1,
			days = val.getDate(),
			year = val.getFullYear();
			return month + "-" + days + "-" + year;
		}
	}
);

Open in new window


The JQRangeSlider site says to use the following code to extract the minimum and maximum date as defined on the slider.

var dateValues = $("#slider").dateRangeSlider("values");
console.log(dateValues.min.toString() + " " + dateValues.max.toString());

Open in new window


I am having trouble retrieving the minimum and maximum values for use in my form.

Can anyone suggest a solution?

(My form validation code)
function validate(){
//THIS FUNCTION ENSURES THAT THE PROJECT_STATE AND AT LEAST ONE OTHER FIELD ARE SELECTED
	var error=0;
	var a=document.forms["sort"]["project_state"].value;
	if ((a==null || a=="")){
		error=1;
		alert("\"Project State\" is a required field.\n\nPlease select a Project State to continue.");
		return false;
	}//END IF				
	if(error==0){
		document.getElementById("sort").submit();						
	}//END IF
}//END VALIDATE FUNCTION

Open in new window


Thanks.
0
Comment
Question by:evibesmusic
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40230137
What about :
var dateValues = $("#slider").dateRangeSlider("values");
var minDate = dateValues.min.toString();
var maxDate = dateValues.max.toString();
$("#hiddenFieldMin").val( min );
$("#hiddenFieldMax").val( max );

Open in new window


<input type="hidden" id="hiddenFieldMin" name="hiddenFieldMin" />
<input type="hidden" id="hiddenFieldMax" name="hiddenFieldMax" />

Open in new window

0
 

Author Closing Comment

by:evibesmusic
ID: 40241807
@leakim971

Perfect. Works like a charm. Have a great day.
0
 

Author Comment

by:evibesmusic
ID: 40242090
@All:

Here is the final code:

var dateValues = $("#slider").dateRangeSlider("values");
var minDate = dateValues.min.toString();
var maxDate = dateValues.max.toString();
$("#hiddenFieldMin").val( minDate );
$("#hiddenFieldMax").val( maxDate );

Changed:
$("#hiddenFieldMin").val( min );
$("#hiddenFieldMax").val( max );

To:
$("#hiddenFieldMin").val( minDate );
$("#hiddenFieldMax").val( maxDate );
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question