Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking input date agains a file of holidays

Status
Not open for further replies.

Papa Bear

Programmer
Feb 1, 2003
37
GB
Hi All

What I am trying to do is output a message "Holiday" immediately after entering a date using the following JavaScript.
Code:
<script type="text/javascript">
    var noHols = "<%=iNoHols%>"
    function datePickerClosed(dateField) {
        var HolArray = new Array();
        document.getElementById("DateMess").value = noHols;
    }
</script>
It last line will eventually be replaced with
Code:
        document.getElementById("DateMess").value = "Holiday;
There will obviously also be some code to check the date, but first I need to get some variables from ASP. I have set these up using the following
Code:
dim dStartHols(100), dEndHols(100)
holsSql = "SELECT Start_Date, End_Date from lawn_holidays " &_
            "Where UserID='" & Request.Cookies("userid") & "' " &_
            "AND Van=" & iVan
            
response.write holsSql & "<BR>"
set holsRS=DBconn.execute(holsSql)

iNoHols=-1 'because arrays start from zero
if holsRS.BOF and holsRS.EOF then
    response.write "empty" & "<br>"
else
    response.write "Full" & "<br>"
	do until holsRS.eof
        iNoHols = iNoHols + 1
		dStartHols(iNoHols) = holsRS("Start_Date")
		dEndHols(iNoHols) = holsRS("End_Date")
		holsRS.movenext
	loop
    'because arrays start from zero, if 1 holiday, then will have value 0
end if
My problem is reading iNoHols, dStartHols and dEndHols in the JavaScript. You can see I have tried to get iNoHols in the code above and display it in the last line. I have googled this for days and var noHols = "<%=iNoHols%>" seems to be the way to go, but no joy. Can you see what I am doing wrong?

Thanks
 
Can you see what I am doing wrong?

Trying to make javascript 'talk' ASP vBscript. Never ever going to happen. ASP code is done and finished with before the javascript even gets to the browser never mind starts to run.

You either do everything server side with round trips using form data, or use AJAX to 'talk' to the server side system.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Yes Chris absolutely right...
you can stick somewhere in javascript array of holidays and check against that array or use ajax call from javascript to server with selected value and get from another asp page on server result
 
Hi

Not totally sure I understand, but from the point of view of javascript being able to see the asp - order is everything.

Code:
<%
dim dStartHols(100), dEndHols(100)
holsSql = "SELECT Start_Date, End_Date from lawn_holidays " &_
            "Where UserID='" & Request.Cookies("userid") & "' " &_
            "AND Van=" & iVan
            
response.write holsSql & "<BR>"
set holsRS=DBconn.execute(holsSql)

iNoHols=-1 'because arrays start from zero
if holsRS.BOF and holsRS.EOF then
    response.write "empty" & "<br>"
else
    response.write "Full" & "<br>"
	do until holsRS.eof
        iNoHols = iNoHols + 1
		dStartHols(iNoHols) = holsRS("Start_Date")
		dEndHols(iNoHols) = holsRS("End_Date")
		holsRS.movenext
	loop
    'because arrays start from zero, if 1 holiday, then will have value 0
end if 
%>
JavaScript:
<script type="text/javascript">
    var noHols = "<%=iNoHols%>";
    function datePickerClosed(dateField) {
        var HolArray = new Array();
        document.getElementById("DateMess").value = noHols;
    }
</script>

As long as iNoHols is set in the first ASP bit, it will be usable in the javascript.

}...the bane of my life!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top