We help IT Professionals succeed at work.

Issue with jquery.datepicker

tekgrl
tekgrl asked
on
I have a form where I'm using jquery.datepicker. In the input field I have a default vaule of "Occupancy Date" that is causing a javascript error since it's not the "mm/dd/yyyy" format called for by the script. Is there anyway around this?
Comment
Watch Question

Since you didn't post your code, this is pretty general...

You could clear the default text out on the onfocus, put something like this in your $(document).ready

$(".form_date").focus(function() {
var val = $(this).val();
if( val === "Occupancy Date" )
{
$(this).val("");
}
});

Author

Commented:
That didn't work. My code is attached. Teh weird thing is that the error comes up on page load not on form submit.
<script type="text/javascript" charset="utf-8">
	Date.firstDayOfWeek = 0;
	Date.format = 'mm/dd/yyyy';
	$(function()
	{
		$('.date-pick').datePicker()
	});
</script>
</head>
<body id="contact">
	<div id="form-wrapper">
		
		<form class="cmxform" id="commentForm" name="contactform" method="post" action="send-form.php" target="_self">
		
			<img src="images/head-contact-us.png" width="92" height="14" alt="contact us" style="padding-bottom: 7px;">

						<div>
				<input  type="text" name="firstName" id="firstName" class="required" maxlength="50" size="20" value="First name" onclick="this.select()">
			</div>
			<div>
				<input  type="text" name="lastName" id="lastName" class="required" maxlength="50" size="20" value="Last name" onclick="this.select()">
			</div>
			<div>
				<input  type="text" name="phone" id="phone" class="required" class="phone" maxlength="12" size="20" value="Phone number" onclick="this.select()">
			</div>
			<div>
				<input  type="text" name="email" id="email" class="required email" maxlength="80" size="20" value="Email address" onclick="this.select()">
			</div>
			<div style="padding-bottom: 11px;">
				<select name="size" class="styled" />
    				<option value="studio">Studio</option>
					<option value="1bed">1 Bedroom</option>
					<option value="2bed">2 Bedroom</option>
				</select>
			</div>
						<div>
							<input name="date1" id="date1" class="date-pick" maxlength="10" value="Date of Occupancy" onclick="this.select()" style="width: 139px;" />
						</div>
			<div style="padding-bottom: 7px;">
				<textarea name="comments" cols="30" rows="2" maxlength="400">Comments</textarea>
			</div>
			<input type="image" src="images/btn-submit-off.png" class="btn" value="Submit" alt="Submit">
		
	</form>			
			
	</div>
</body>

Open in new window

in your script, the capitalization is wrong and you are missing a ;

should be:

	$(function()
	{
	 	var what = $('.date-pick');
		$('.date-pick').datepicker();
	});

Open in new window

oops, the what was my debugging...

	$(function()
	{
		$('.date-pick').datepicker();
	}); 

Open in new window

Author

Commented:
Still having the original issue with default value.
please see http://jsfiddle.net/EU8rP/2/ - it works and ignores and overwrites the default value

Author

Commented:
When I put that code in I got an error on this line:

 $('.date-pick').datepicker();
Object doesn't support this method or property

When I change datepicker back to datePicker I get the original error on the date.js file.
Hm.  Maybe you have more than one problem.  I just went with the code you posted, and the error I was getting was Object doesn't support this method or property where the capitalization on datepicker was incorrect.  Fixing that fixed the problem for me and made the calendar work (as seen in the jsfiddle example).  Do you have other code you are using in addition to what you posted?