views:

412

answers:

2

Hi,

I can't get the jQuery datepicker to work. I have followed everything from the jQuery UI manual. Can you please check my code below?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link type="text/css" href="js/jquery_theme/jquery-ui.css" rel="stylesheet" />
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="js/ui.core.js"></script>
<script type="text/javascript" src="js/ui.datepicker.js"></script>

<script language="javascript">
$(function() {

 $("#test_input").datepicker();

});
</script>

</head>

<body>
<input type="text" name="test_input" id="test_input" />
</body>
</html>

Thank you for your time :)

A: 

Try placing your tag at the bottom of the page (after the body tag), or do this

 $(document).ready( function() {

   $("#test_input").datepicker();

 });

The javascript gets interpreted before the input(#test_input) tag is loaded into the dom, so that might be the problem.

Rishav Rastogi
Code inside `$(document).ready( function() { ... } );` gets executed when the page has finished loading, despite its position inside it.
Alex Bagnolini
i know, thats why the 'or' in my answer
Rishav Rastogi
you can do either , place his code at the bottom or use $(document).ready() ...
Rishav Rastogi
He actually is using the shortcut to the document.ready function already. If a function is passed into the jQuery object, it automatically waits until the document is ready to run it. $(function(){ /* the document is ready */ });
Alex Sexton
nice thanks. Didn't know that.. :)
Rishav Rastogi
+3  A: 

Correct your <script> tag. You can then handle the returned date like this:

<script type="text/javascript">
  $(document).ready(
      function() {
          $('#input_test').datepicker(
              {
                  onClose: function(dateText, inst) {
                          alert("My date is: " + dateText);
                      }
              }
          );
      }
  );
</script>
Alex Bagnolini
thanks but it didn't work.. hmm..
Obay
i think i got it! i changed "input_test" to "test_input" (lol :P) then i used the <div> technique and changed "onClose" in your script to "onSelect" ;) thanks man!
Obay