ztimer Posted January 22, 2015 Share Posted January 22, 2015 I have trouble calling timepicker with class and passing data-values to the script. So what i have so far is one loop that for each entry it will create foreach($data as $value){ $min_hour = $value['minhour']; // returns value from DB like 7 to 12 echo '<td><input type="text" value="" class="schedule-timepicker" data-minhour="'.$min_hour.'" data-minminutes="30" data-maxhour="17" data-maxminutes="00"></td>'; } Then in js file I have $(document).ready(function(){ $('.schedule-timepicker').timepicker({ timeFormat: 'HH:mm:ss', minDate: new Date(1, 1, 1, $('.schedule-timepicker').data('minhour'), 00), maxDate: new Date(1, 1, 1, $('.schedule-timepicker').data('maxhour'), 00), }); }); Problem is that the timepicker is called out and works but every input has the same minimum hours value as the first one. Please help how to resolve this. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/294118-call-timepicker-with-data-values/ Share on other sites More sharing options...
cyberRobot Posted January 22, 2015 Share Posted January 22, 2015 Have you tried looping with .each()? $(document).ready(function(){ $('.schedule-timepicker').each(function() { alert($(this).attr('data-minhour')); }); }); Quote Link to comment https://forums.phpfreaks.com/topic/294118-call-timepicker-with-data-values/#findComment-1503740 Share on other sites More sharing options...
ztimer Posted January 22, 2015 Author Share Posted January 22, 2015 Yes I get alert with different value for each entry. Quote Link to comment https://forums.phpfreaks.com/topic/294118-call-timepicker-with-data-values/#findComment-1503768 Share on other sites More sharing options...
Solution cyberRobot Posted January 22, 2015 Solution Share Posted January 22, 2015 Were you able to adapt the code to work with the timepicker plugin? Perhaps something like the following will work: $(document).ready(function(){ $('.schedule-timepicker').each(function() { $(this).timepicker({ timeFormat: 'HH:mm:ss', minDate: new Date(1, 1, 1, $(this).data('minhour'), 00), maxDate: new Date(1, 1, 1, $(this).data('maxhour'), 00), }); }); }); Note that the timepicker code is untested. 1 Quote Link to comment https://forums.phpfreaks.com/topic/294118-call-timepicker-with-data-values/#findComment-1503776 Share on other sites More sharing options...
ztimer Posted January 22, 2015 Author Share Posted January 22, 2015 Wow. It worked out of box. Thanks. I did not realize to use "this" and not to call it again ..Lesson learned. First use class and then use thisYou can't believe how happy this made me. I can continue now with the code. Thanks for this.. Quote Link to comment https://forums.phpfreaks.com/topic/294118-call-timepicker-with-data-values/#findComment-1503777 Share on other sites More sharing options...
cyberRobot Posted January 22, 2015 Share Posted January 22, 2015 No problem; glad to help! Quote Link to comment https://forums.phpfreaks.com/topic/294118-call-timepicker-with-data-values/#findComment-1503778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.