Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple JavaScript datepicker bug?

I'm using jQuery datepicker, and I'm using this code ...

<script>
    $(function() {
      $("#datepicker").datepicker();
      //$("#datepicker2").datepicker();
    });
</script>

...at the header of my page. Meanwhile, with PHP, I want to call it an indefinite number of times.

But I can't use this function to place "datepicker" more that once if there is only one: $("#datepicker").datepicker(); on the function.

How can I call this function an indefinite number of times?

like image 243
Sammy Avatar asked Feb 27 '26 00:02

Sammy


2 Answers

call a class ..

$(".datepicker").datepicker();

and you can call indefinite number of time ..just that all your input should have the class datepicker

example

<input name="test1" class="datepicker" />
<input name="test2" class="datepicker" />
.......
like image 96
bipen Avatar answered Mar 01 '26 12:03

bipen


IDs are meant to be unique.

Switch your #datepicker for .datepicker on your html and on your jQuery.

like image 35
Bigood Avatar answered Mar 01 '26 12:03

Bigood