user2148334
user2148334

Reputation: 11

Datepicker some problems with opening

I use in my web app datepicker jquery but it I have some problem: I have two tabs in one of them I have two menu, were I use datepicker in each other of menu. And second tab has one menu and there I also use datepicker. When I load my web page, and try to set some date with datepicker it is work (datepicker was opened). But after that I go to the second menu in this tab or another tab and try to set some date in my input date, but datepicker not opens. I also use ajax in this page. Whats wrong? thx!

  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

  <input type="text" name="dateTime" id="dateTime" placeholder="yyyy-mm-dd" required />
  <script>
     $(function() {
       $("#dateTime").datepicker({ dateFormat: "yy-mm-dd" , changeMonth: true });
     });
  </script>

Upvotes: 1

Views: 189

Answers (1)

Sushanth --
Sushanth --

Reputation: 55750

The problem is the selector

$("#dateTime")

ID in a page is supposed to be unique

Use classes instead.

Because you are using a ID selector it tried to find the first instance of the element. Once it finds it, stops searching again. So it will never be applied to the element in the other tab..

Change

<input type="text" name="dateTime" id="dateTime"

to

<input type="text" name="dateTime" class="dateTime"

And then change the selector to

$(".dateTime")

Upvotes: 1

Related Questions