Link to home
Start Free TrialLog in
Avatar of BR
BRFlag for Türkiye

asked on

javascript date picker in php while loop

Dear Experts,

I have a date picker, it is works like input type= date

it works however, when I use it in a loop, it only works on the first row.
Although it has the same id, and very same code, it doesn't work on the other rows.
I have 250 rows, but the date picker works only at the first row.
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

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

Open in new window


I echo this in the while loop

"<input type=text id='datepicker' name=cekilecektarih style=width:70px; />"; 

Open in new window

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

I echo this in the while loop
"<input type=text id='datepicker' name=cekilecektarih style=width:70px; />";

Open in new window

you probably need to put a unique id for your each datepicker, like :

<input type=text id='datepicker1' name=cekilecektarih style=width:70px; />
<input type=text id='datepicker2' name=cekilecektarih style=width:70px; />
...
<input type=text id='datepickerN' name=cekilecektarih style=width:70px; />

Open in new window

when you call the function, try to include that id into your function
ASKER CERTIFIED SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BR

ASKER

Thank you Shaun Vermaak
In HTML and CSS, the id attribute must be unique.  The class attribute can name several elements.  Your id and class attributes can be collections of CSS selector names, such as class="datepicker urgent action".  This is what empowers the "cascade" of styles.

In jQuery, the selector starts with # if you want to select by id and starts with . (dot) if you want to select all elements of a matching class.

The W3Schools has good documentation about this!
http://www.w3schools.com/css/css_intro.asp
Avatar of BR

ASKER

Thank you Ray Pasuer,