简体   繁体   中英

Call SQL Server procedure with list of dates to disable on jquery datepicker

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?

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM