0

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?

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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

Comments

0

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.

Comments

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.