0

I have implementation a j query date and time picker into a website. The picker is working and when i select a date and time it saves to a database. what i can not figure out how to do is disable any date and times which are in the database, so that no one can select a time on a date which has previously been selected. This is my code for the jquery picker, searching the database for the valus isnt a problem im just not sure how to set it in the picker itself:

<script type="text/javascript">
$(function(){

$('*[name=date2]').appendDtpicker({"inline": true,
"allowWdays": [1, 2, 3, 4, 5], // 0: Sun, 1: Mon, 2: Tue, 3: Wed, 4:     Thr, 5: Fri, 6: Sat
"futureOnly": true,
"autodateOnStart": false
});

$('#btn_input').on('click', function(){
    var input = $('*[name=date2]').handleDtpicker('getDate');
    var select = document.getElementById("doctor").value;
    var select1 = document.getElementById("patient").value;
    console.log(input);

$.post( "backend2.php", { 
'input':input,
'select':select,
'select1':select1
}).done(function( data ) {
alert( "You have selected" + data );


});

});
});

</script>
  • You should create JSFiddle with this code and URL to DateTimePicker plugin. I created it for you: http://jsfiddle.net/670ayxdy/ – Tomasz Racia May 24 '15 at 19:10

1 Answers1

-1

If you read the documentation of datetimepicker (if this is the plugin you are using)

http://xdsoft.net/jqplugins/datetimepicker/

it has a disabledDates option which can be used the same way as the example of the post mentioned. Build the array of dates with your scripting language.

From the docs:

{disabledDates: ['01.01.2014','02.01.2014','03.01.2014','04.01.2014','05.01.2014','06.01.2014'], formatDate:'d.m.Y'}

From this post:

Jquery UI datepicker. Disable array of Dates

It explains how to disable dates. What you can do is build the array of disabled dates with a query from the database and echoing it in the javascript with whatever scripting language you are using.

Community
  • 1
  • 1
Fabrizio Mazzoni
  • 1,831
  • 2
  • 24
  • 46
  • You're taling about Datepicker plugin not DateTimePicker plugin. The one from question doesn't have `beforeShowDay` property – Tomasz Racia May 24 '15 at 18:51
  • It doesnt seem to be working for me, its affecting the running of the picker. I have tried looking through the js code from the source files but i cant figure out which property is the same as "before showday" – Niamh Mac Gualraic May 24 '15 at 18:58
  • Are you getting any error in js console? And how is it affecting? – Fabrizio Mazzoni May 24 '15 at 18:59
  • i am using the following: http://mugifly.github.io/jquery-simple-datetimepicker/ The picker is set as inline so it is always displayed, and the picker disappeared on the screen when i added the code – Niamh Mac Gualraic May 24 '15 at 19:03
  • OK. Why don't you try this one: http://xdsoft.net/jqplugins/datetimepicker/ which has the option you need built in? it very similar also in design. – Fabrizio Mazzoni May 24 '15 at 19:05
  • I cant change now, this is a project for my final year dissertation, the demo day is tomorrow, this is the only thing bothering me, if i couldnt get it working i was just gona to have an alert that said the date and time selected has already been booked, but its just not as accessible, i thought there must be a method for this picker when this is the purpose its created for – Niamh Mac Gualraic May 24 '15 at 19:08
  • There is a similar issue on their GitHub page added as a bug on December last year... You would save more time by changing the plugin rather than still looking for the answer. Good luck with demo tomorrow! ;) – Tomasz Racia May 24 '15 at 19:26