0

I cant get jquery's date picker to work on my page. I have a forum post on codecall if anyone wants more details. Here's a link http://forum.codecall.net/topic/70462-copy-and-paste-date-picker-javascipt/. Here's my code that is associated with this page. When I click the text fields the datepicker doesn't show up. Why? Can anyone see the problem?

<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.21.custom.min.js"></script>
$(function() {
$( "#start_date" ).datepicker();
});
$(function() {
$( "#end_date" ).datepicker();
});

<div id="dateField"> 
<p> 
Start Date: <input type="TEXT" 
name="start_date" id="startDate" 
value="" /> 
</p> 
<p> 
End Date: <input type="TEXT" 
name="end_date" id="endDate" 
value="" /> 
</p> 
<small>Dates Should be in the format DD/MM/YYYY</small> 
</p> 
</div>  
1
  • 3
    Your ids are startDate and endDate, not start_date and end_date. Fix that, and it works. jsfiddle.net/2dVC3 P.S. Put your script in a <script> tag. Commented Jun 25, 2012 at 19:45

2 Answers 2

1

Switch your Id and name tags around. An ID attribute has to be inside of the $('ID').datepicker() , not name.

<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.21.custom.min.js"></script>

<script type="text/javascript">
$(function() {
$( "#start_date" ).datepicker();
});
$(function() {
$( "#end_date" ).datepicker();
});
</script>

<div id="dateField"> 
<p> 
Start Date: <input type="TEXT" 
id="start_date" name="startDate" 
value="" /> 
</p> 
<p> 
End Date: <input type="TEXT" 
id="end_date" name="endDate" 
value="" /> 
</p> 
<small>Dates Should be in the format DD/MM/YYYY</small> 
</p> 
</div>  
Sign up to request clarification or add additional context in comments.

3 Comments

end_date = id and endDate= name . It's other way around in your code
Make sure to put your script in <script> tags :-P
There's alot of code omitted here so as far as the script tag goes just know it's there
1

Wrap your jQuery UI datepicker code in a <script> tag, and mark it as javascript with the type attribute. Use a single document ready block for your two datepicker calls. Ensure you're using the correct IDs of your elements.

<script type="text/javascript">
   $(document).ready(function() {

        $("#startDate").datepicker();
        $("#endDate").datepicker();
   });
</script>

3 Comments

$(function() { is shorthand for $(document).ready(function() {.
The type attribute is optional in HTML5 :-)
Unsure these comments can strictly eliminate my answer to this problem. The biggest problem was the jQuery code wasn't even in a script block. 2nd problem is that we aren't even sure he's in an HTML5 document here. 3rd, you don't want to have 2 document ready blocks in this context. This question shows signs of cargo culting, so using/encouraging the shorthand isn't useful to the OP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.