Solved

Date Validations Using Dropdownlist

Posted on 2011-09-29
3
205 Views
Last Modified: 2012-05-12
Hi,
I am Developing A Form ,In that Form I am using three dropdown lists respectively they are drdDay,drdMonth,drdyear. The drdDate  contains 1-31 days and drdMonth contains 1-12 and drdyear Contains Previous year and Present year. Now I Validating allow to select only 10 days less than the Present/Current date. If any one select more than the Present/Current date and select lessthan 10 days raise an Error.I am Really confusing  to handle this Any one Help me to Over come this Problem and  i don't want to use ajax calender control. If any Other alternative than the Ajax Calender Control and Dropdown list please suggest me. Thank You.
0
Comment
Question by:CPSRI
3 Comments
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36883485
How about adding jquery validation to dropdownlists?
0
 
LVL 3

Expert Comment

by:exceter
ID: 36888784
What error do you have?
could you paste here that part of your code ...
0
 
LVL 9

Accepted Solution

by:
richard_hughes earned 500 total points
ID: 36890755
Hello CPSRI

This code will produce an error is the date selected is either 10 days before or 10 days after today.

NOTE: if you are unfamiliar with jQuery or are unsure where to download it, you can get it officially here for free: http://jqueryui.com/download

Thanks,

Richard Hughes
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>Date Example</title>
		<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
		<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
		<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
		<script type="text/javascript">

			$(document).ready(function () {

				$("#textDate").datepicker({

					onSelect: function (dateText, i) {

						var date = $(this).datepicker("getDate");

						var today = new Date();

						var difference = today - date;

						var days = (((difference / 1000) / 60) / 60) / 24;

						if (days < -10 || days > 10) {

							// put your error code here
							alert("The date you entered is out of range.");
						}
					}
				});
			});

		</script>	
	</head>
	<body>

		<p><label for="textDate">Date: </label><input type="text" id="textDate" /></p>

	</body>
</html>

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project

679 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