deross
asked on
Mixing asp and JavaScript
I have a procedure that populates an event calendar. Below is the portion of code I am having trouble with:
<%
Set Conn = Server.CreateObject("ADODB .Connectio n")
Conn.Open("DRIVER={Microso ft Access Driver (*.mdb)}; DBQ=d:\myspace\ftz12\tn867 21\cashcom .ca\db\app ointment_d ates.mdb")
sql = "select Name, ApptDate from apptdates where Name = '" & strName & "' order by Name, ApptDate"
Set RS = Conn.Execute(sql)
Do While NOT RS.EOF
intMonth = RS("ApptDate").Value
intMonth = Left(intMonth,2)
intDay = RS("ApptDate").Value
intDay = Mid(intDay,4,2)
Session("Day") = intDay
Session("Month") = intMonth
Session("Event") = Session("Day") & "," & Session("Month") & "," & Session("Day") & "," & Session("Month") & ","
%>
<script type="text/javascript">
var months = ["January","February","Mar ch","April ","May","J une","July ","August" ,"Septembe r","Octobe r","Novemb er","Decem ber"];
var daycounts = [31,28,31,30,31,30,31,31,3 0,31,30,31 ];
var firstdays = [2,5,5,1,3,6,1,4,0,2,5,0];
var appointments = [
[<%=Session("Event")%>"App ointment"]
];
</script>
<%
RS.MoveNext
loop
%>
<%
Set Conn = Server.CreateObject("ADODB
Conn.Open("DRIVER={Microso
sql = "select Name, ApptDate from apptdates where Name = '" & strName & "' order by Name, ApptDate"
Set RS = Conn.Execute(sql)
Do While NOT RS.EOF
intMonth = RS("ApptDate").Value
intMonth = Left(intMonth,2)
intDay = RS("ApptDate").Value
intDay = Mid(intDay,4,2)
Session("Day") = intDay
Session("Month") = intMonth
Session("Event") = Session("Day") & "," & Session("Month") & "," & Session("Day") & "," & Session("Month") & ","
%>
<script type="text/javascript">
var months = ["January","February","Mar
var daycounts = [31,28,31,30,31,30,31,31,3
var firstdays = [2,5,5,1,3,6,1,4,0,2,5,0];
var appointments = [
[<%=Session("Event")%>"App
];
</script>
<%
RS.MoveNext
loop
%>
What is the problem that you are having?
ASKER
The sample event calendar code has the following for var appointments:
var appointments = [
[15,3,13,4,"Holiday in New Zealand"],
[12,06,12,06,"my birthday"],
[28,8,2,9,"Trip to Paris"],
[22,11,22,11,"Party with colleagues"],
[20,12,30,12,"Christmas with family"]
];
By using my session variable and loop procedure, I am only getting the last record from the database.
var appointments = [
[15,3,13,4,"Holiday in New Zealand"],
[12,06,12,06,"my birthday"],
[28,8,2,9,"Trip to Paris"],
[22,11,22,11,"Party with colleagues"],
[20,12,30,12,"Christmas with family"]
];
By using my session variable and loop procedure, I am only getting the last record from the database.
I think that I am still missing something. If you do not include your session variable information, do you get all of your records?
FtB
FtB
ASKER
I think the problem is that as the database loops, the var appointments variable gets changed to the currenct record until it reaches the end at which time the var appointments variable is set to the last record. As you can see from the sample above, there are five records that were manually typed in. What I need is, instead of the var appointments variable being replaced for each new record, I need to append the var appointment variable with each new record.
try this:
<%
Set Conn = Server.CreateObject("ADODB .Connectio n")
Conn.Open("DRIVER={Microso ft Access Driver (*.mdb)}; DBQ=d:\myspace\ftz12\tn867 21\cashcom .ca\db\app ointment_d ates.mdb")
sql = "select Name, ApptDate from apptdates where Name = '" & strName & "' order by Name, ApptDate"
Set RS = Conn.Execute(sql)
%>
<script type="text/javascript">
var months = ["January","February","Mar ch","April ","May","J une","July ","August" ,"Septembe r","Octobe r","Novemb er","Decem ber"];
var daycounts = [31,28,31,30,31,30,31,31,3 0,31,30,31 ];
var firstdays = [2,5,5,1,3,6,1,4,0,2,5,0];
var appointments = new Array();
<%
Do While NOT RS.EOF
intMonth = RS("ApptDate").Value
intMonth = Left(intMonth,2)
intDay = RS("ApptDate").Value
intDay = Mid(intDay,4,2)
Session("Day") = intDay
Session("Month") = intMonth
Session("Event") = Session("Day") & "," & Session("Month") & "," & Session("Day") & "," & Session("Month") & ","
%>
appointments[appointments. length] = new Array( <%=Session("Event")%>"Appo intment" );
<%
RS.MoveNext
loop
%>
</script>
Hope it helps..
<%
Set Conn = Server.CreateObject("ADODB
Conn.Open("DRIVER={Microso
sql = "select Name, ApptDate from apptdates where Name = '" & strName & "' order by Name, ApptDate"
Set RS = Conn.Execute(sql)
%>
<script type="text/javascript">
var months = ["January","February","Mar
var daycounts = [31,28,31,30,31,30,31,31,3
var firstdays = [2,5,5,1,3,6,1,4,0,2,5,0];
var appointments = new Array();
<%
Do While NOT RS.EOF
intMonth = RS("ApptDate").Value
intMonth = Left(intMonth,2)
intDay = RS("ApptDate").Value
intDay = Mid(intDay,4,2)
Session("Day") = intDay
Session("Month") = intMonth
Session("Event") = Session("Day") & "," & Session("Month") & "," & Session("Day") & "," & Session("Month") & ","
%>
appointments[appointments.
<%
RS.MoveNext
loop
%>
</script>
Hope it helps..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1. Why need to store in Session when code is in the Same page ?
2. From what u give, is this line correct, the first and second Date the always the Same ?
Session("Day") & "," & Session("Month") & "," & Session("Day") & "," & Session("Month") & ","
here is my Version
<%
Set Conn = Server.CreateObject("ADODB .Connectio n")
Conn.Open("DRIVER={Microso ft Access Driver (*.mdb)}; DBQ=d:\myspace\ftz12\tn867 21\cashcom .ca\db\app ointment_d ates.mdb")
sql = "select Name, ApptDate from apptdates where Name = '" & strName & "' order by Name, ApptDate"
Set RS = Server.CreateObject("ADODB .Recordset ")
RS.Open "sql", DBconn, 2, 2
if Not DBrs.EOF Then
Record = RS.GetRows()
End if
RS.Close
Conn.Close
%>
<script type="text/javascript">
var months = ["January","February","Mar ch","April ","May","J une","July ","August" ,"Septembe r","Octobe r","Novemb er","Decem ber"];
var daycounts = [31,28,31,30,31,30,31,31,3 0,31,30,31 ];
var firstdays = [2,5,5,1,3,6,1,4,0,2,5,0];
var appointments = new Array();
<%
if IsArray(Record) then
for i=0 to UBound(Record,2)
intMonth = Left( Record(1,i),2)
intDay = Mid(Record(1,i),4,2)
event = intDay & "," & intMonth & "," & intDay & "," & intMonth & ","
Response.write "appointments[appointments .length] = new Array( " & even &"'Appointment' );"
next
end if
%>
</script>
2. From what u give, is this line correct, the first and second Date the always the Same ?
Session("Day") & "," & Session("Month") & "," & Session("Day") & "," & Session("Month") & ","
here is my Version
<%
Set Conn = Server.CreateObject("ADODB
Conn.Open("DRIVER={Microso
sql = "select Name, ApptDate from apptdates where Name = '" & strName & "' order by Name, ApptDate"
Set RS = Server.CreateObject("ADODB
RS.Open "sql", DBconn, 2, 2
if Not DBrs.EOF Then
Record = RS.GetRows()
End if
RS.Close
Conn.Close
%>
<script type="text/javascript">
var months = ["January","February","Mar
var daycounts = [31,28,31,30,31,30,31,31,3
var firstdays = [2,5,5,1,3,6,1,4,0,2,5,0];
var appointments = new Array();
<%
if IsArray(Record) then
for i=0 to UBound(Record,2)
intMonth = Left( Record(1,i),2)
intDay = Mid(Record(1,i),4,2)
event = intDay & "," & intMonth & "," & intDay & "," & intMonth & ","
Response.write "appointments[appointments
next
end if
%>
</script>
i think your code sequences must have some change, and in your code [<%=Session("Event")%>"App ointment"] , the word "Appointment" is just a text, or you mean RS("appointment"), you see, you define so many session variables in the do while loop, the session vaiables will be defined as many times as your recordset recordcount, no meaning for using session... please check your sessions variables definitions carefuly
after that, i think you can define your new array appointment size with the property recordset.recordcount.