0

I have a Classic ASP system with jquery datepicker, I want do disable automatically some days. This dates will automatically populate the array that disable dates. (today is manual using the function)

var disableddates = ["10-12-2015", "11-20-2015", "12-21-2015", "12-22-2015", "12-23-2015", "12-24-2015", "12-25-2015", "12-28-2015", "12-29-2015", "12-30-2015", "12-31-2015", "1-1-2016"];

I have a SQL Server procedure that gives me a list with all this dates. How can I call it before open the datepicker with all this dates disabled?

  • I don't understand the question. Are you asking how to pass these dates to sql or are you asking how to disable the dates received or something else entirely? – Sean Lange Dec 04 '15 at 17:47
  • I have this dates on SQL I need to pass this dates do datepicker to disable this. – user2046486 Dec 04 '15 at 18:23
  • Possible duplicate of [Jquery UI datepicker. Disable array of Dates](http://stackoverflow.com/questions/15400775/jquery-ui-datepicker-disable-array-of-dates) – Sean Lange Dec 04 '15 at 18:57
  • Sean,The problem is that on the post you said, the dates are disable manually, and I need to do this dinamically. Could your help? – user2046486 Dec 07 '15 at 11:13
  • Did you see the link I posted? It has an example of how to do this. – Sean Lange Dec 07 '15 at 15:05
  • Yes, I did, but the example show it manually, I need it dinamically. I need to call a procedure before showing the calendar to disable the dates. – user2046486 Dec 07 '15 at 18:31

2 Answers2

0

The example in the answer to the other question isn't manual (or dynamic); it just isn't showing all of the preceding steps. What you want is to, basically, write your JavaScript using VBScript - or, to put it another way, use server-side code to write your client-side code. Of course, if you think about it, you always use server-side code to write your client-side code, but it's not always so obvious.

<%
dim ForbidDates, sql, rs
'...
'... add code here to call the SQL Server procedure & put the results into a recordset...
'...
ForbidDates = rs.GetString(,,"','","'",)
'- you may need code to clean up the beginning/end of ForbidDates,
'- e.g. removing any extraneous commas from the end, making sure
'- the first value has quotes around it correctly, etc.
'...
%>
<script type="text/javascript">
var array = [<%=ForbidDates%>]
$('input').datepicker({
    beforeShowDay: function(date){
        var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
        return [ array.indexOf(string) == -1 ]
    }
});
</script>
Martha
  • 3,932
  • 3
  • 33
  • 42
0

I called the procedure beore, and passed the result to a variable: var disableddates = <%=vardatasfim %>

The variable disableddates is used on the function that disable weekends and is called on beforeShowDay