fbernier
fbernier

Reputation: 12288

using jquery-ui

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?

Upvotes: 0

Views: 193

Answers (4)

Ionuț G. Stan
Ionuț G. Stan

Reputation: 179109

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 language=javascript>
    $(function () {
        $('#date').datepicker();
    });
</script>

Now it should work.

Upvotes: 1

Sruly
Sruly

Reputation: 10540

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.

Upvotes: 0

ppiotrowicz
ppiotrowicz

Reputation: 4614

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

Upvotes: 0

cletus
cletus

Reputation: 625037

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.

Upvotes: 4

Related Questions