shield1948 Posted August 7, 2013 Share Posted August 7, 2013 (edited) Hello, I'm trying to retrieve dates from the database based on a selection. If a user selects singer A for example, then I'm going through the database and get the unavailable dates of singer A. var unavailableDates; function unavailable(date) { dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear(); if ($.inArray(dmy, unavailableDates) == -1) { return [true, ""]; } else { return [false, "", "Unavailable"]; } } $(document).ready(function() { $("#datepicker").datepicker({ dateFormat: 'yy-mm-dd', beforeShowDay: unavailable, minDate: 0, firstDay: 1, // rows starts on Monday changeMonth: true, changeYear: true, showOtherMonths: true, selectOtherMonths: true, altField: '#date_due', altFormat: 'yy-mm-dd' }); $('#datepicker').focus(function(){ //alert($('#name').html()); $.ajax({ url: 'getDates.php', data: "artist_id="+$('#name').html(), dataType: 'json', success: function(data) { alert(data) } }); }) }); Everything works fine. Using the "getDates.php" I retrieved the dates and pass them through the function. But how can I pass the data (after success: function) to the unavailable dates above? I have the dates from database but I don't know how to link them with the array "unavailableDates" (line 1) in order to show unavailable dates in datePicker. Edited August 7, 2013 by shield1948 Quote Link to comment https://forums.phpfreaks.com/topic/280937-jquery-datepicker-unavailable-dates-from-database/ Share on other sites More sharing options...
mac_gyver Posted August 8, 2013 Share Posted August 8, 2013 assuming you are json_encoding the data, replace the alert(data) with - unavailableDates = data; Quote Link to comment https://forums.phpfreaks.com/topic/280937-jquery-datepicker-unavailable-dates-from-database/#findComment-1443964 Share on other sites More sharing options...
shield1948 Posted August 8, 2013 Author Share Posted August 8, 2013 (edited) Thanks mac_gyver. I've already did that... but I know what the problem was. Basically I just needed to store the data in the unavailableDates array. I did that yesterday but I forgot to change the date format (from yyyy-mm-dd to dd-mm-yyyy). Now it works fine. One little problem left, I need to click twice on datepicker in order to show the unavailable dates... Does anyone know why? :/ Edited August 8, 2013 by shield1948 Quote Link to comment https://forums.phpfreaks.com/topic/280937-jquery-datepicker-unavailable-dates-from-database/#findComment-1444073 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.