Solved

How to extract user defined date range values using JQRangeSlider?

Posted on 2014-07-29
3
1,027 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How Close unsubmited attempts 10 42
converting document.write() to innerHTML 7 43
Use "if not" in a condition 2 18
How do i use the await event in php echo 5 13
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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 …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

680 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