views:

139

answers:

4

Hi, I'm trying to pop a simple datepicker but can't or I don't know what reason. here's my code:

<!DOCTYPE html>
<html>
<script type="text/javascript" src="jquery/jquery.js"> </script>
<link type="text/css" href="css/smoothness/jquery.css" rel="Stylesheet" />
<script type="text/javascript" src="jquery/jquery-ui.js"> </script>   

<script type="text/javascript">
$('#date').datepicker();
 </script>
<body>
<input type="text" name="date" id="date" />
</body>
</html>

I'm running an apache server with all the correct path. Anyone may know why this is not working?

A: 

I'm no expert but you're missing <head> tag.

ppiotrowicz
+4  A: 

Try:

$(function() {
  $("#date").datepicker();
});

The point being that your check probably fails because the date element doesn't exist yet, particularly since it isn't declared until after the the script that looks for it.

cletus
+1  A: 

You should put your datepicker related code after the INPUT tag. But, as far as I know, the datepicker component requires that you call it after page load, so your code should become this:

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

Now it should work.

Ionuț G. Stan
A: 

It seems that the issue was solved. You had to put it in a $(document).ready() function.

I would just add one more thing about JQuery-UI. If all you need is the datepicker you shouldnt include the whole UI package. Go to the JQuery-UI site and you can customize your download. Mark off the things you need and it will give you a file with only the minimum. This will make you pages load faster.

Sruly