Solved

How to extract user defined date range values using JQRangeSlider?

Posted on 2014-07-29
3
1,044 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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)

752 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