Solved

JQuery Calendar - won't disappear on date selection

Posted on 2011-03-15
1
383 Views
Last Modified: 2012-05-11
Hi I had this problem before but realised it was caused by bad JQuery syntax.  I'm a JQuery newbie so please bear with me :-).  It was ever since I added the code to set the date field to tomorrow's date that it started going wrong.  I'd be grateful if someone could tell me where I'm going wrong in my syntax.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>Cross Keys Hotel, London/title>

<link rel="stylesheet" type="text/css" href="styles/baseline.css" />
<link rel="stylesheet" type="text/css" href="styles/jquery.lightbox-0.5.css" media="screen" />
<link rel="stylesheet" type="text/css" href="styles/jquery-ui.css" media="screen" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.min.js"></script>

<script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script>

<script type="text/javascript">

$(document).ready(function() {

$('#Date').datepicker({
			onSelect: function(dateText, inst) {
				var s = dateText.split("/");
				$("#$DAY$").val(s[2]);
				$("#$MONTH$").val(s[1]);
				$("#$YEAR$").val(s[0]);
			}

		}); 

$("#Date").datepicker('option', {dateFormat: 'dd/mm/yy'}); 

var myDate = new Date();
    var day = myDate.getDate() + 1;
    var month = myDate.getMonth() + 1;
    var ukDate = day + '/' + month + '/' + myDate.getFullYear();
    $("#Date").val(ukDate);

$('a[rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel

});

</script>
</head>



<body id="county" class="booking"> 

<div id="booking">
<h3>Find &amp; Book</h3>
<form name="bookingForm" id="bookingForm" method="post" action="http://www.hotelexec.co.uk/external.asp" autocomplete="off">
<fieldset>
<input name="$LICENCE$" type="hidden" value="xxxxxx" />
<input name="$SMOKING$" type="hidden" value="" />

<input name="$SOURCE$" type="hidden" value="" />
<input name="$LEDGER$" type="hidden" value="" />
<input name="$DAY$" id="Day" type="hidden" value="" />
<input name="$MONTH$" id="Month" type="hidden" value="" />
<input name="$YEAR$" id="Year" type="hidden" value="" />
<label for="Date">Arrival <br/> Date</label>
<input id="Date" name="Date" type="text" value="" autocomplete="off" class="required" />
<label for="Nights">Number <br/> of nights</label>
<!--<input id="Nights" name="$NIGHTS$" type="text" value="1" />-->
<select id="Nights" name="$NIGHTS$">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>

<option value="20">20</option>
<option value="21">21</option>
</select>
<input type="submit" name="Submit" value="Check for Availability" class="submit" />
</fieldset>
</form>
</div>

</body>
</html>

Open in new window

0
Comment
Question by:Lorna70
1 Comment
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 250 total points
ID: 35142681
Use 1 assignment of the the datepicker to your #Date element.
$('#Date').datepicker({
	onSelect: function(dateText, inst) {
		var s = dateText.split("/");
		$("#$DAY$").val(s[2]);
		$("#$MONTH$").val(s[1]);
		$("#$YEAR$").val(s[0]);
	},
	dateFormat: 'dd/mm/yy'
});

Open in new window

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 discusses how to create an extensible mechanism for linked drop downs.
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)

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now