Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Mixing asp and JavaScript

Posted on 2003-12-06
9
Medium Priority
?
668 Views
Last Modified: 2008-02-01
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.Connection")
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:\myspace\ftz12\tn86721\cashcom.ca\db\appointment_dates.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","March","April","May","June","July","August","September","October","November","December"];
var daycounts = [31,28,31,30,31,30,31,31,30,31,30,31];
var firstdays = [2,5,5,1,3,6,1,4,0,2,5,0];
var appointments = [
[<%=Session("Event")%>"Appointment"]
];
</script>
<%
RS.MoveNext
loop
%>
0
Comment
Question by:deross
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9890047
What is the problem that you are having?
0
 

Author Comment

by:deross
ID: 9890271
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.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9890439
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:deross
ID: 9890463
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.
0
 
LVL 2

Expert Comment

by:abuimad
ID: 9890744
try this:

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:\myspace\ftz12\tn86721\cashcom.ca\db\appointment_dates.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","March","April","May","June","July","August","September","October","November","December"];
      var daycounts = [31,28,31,30,31,30,31,31,30,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")%>"Appointment" );
<%
RS.MoveNext
loop
%>
</script>

Hope it helps..
0
 
LVL 21

Accepted Solution

by:
ap_sajith earned 2000 total points
ID: 9890917
Try this..... You will have to append the values to the session variable as shown below

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:\myspace\ftz12\tn86721\cashcom.ca\db\appointment_dates.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
If Session("Event")="" Then
Session("Event") = "[" & Session("Day") & "," & Session("Month") & "," & Session("Day") & "," & Session("Month") & "]"
Else
Session("Event") = Session("Event") & ",[" & Session("Day") & "," & Session("Month") & "," & Session("Day") & "," & Session("Month") & "]"
End If
%>
<script type="text/javascript">
var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var daycounts = [31,28,31,30,31,30,31,31,30,31,30,31];
var firstdays = [2,5,5,1,3,6,1,4,0,2,5,0];
var appointments = [
<%=Session("Event")%>"Appointment"
];
</script>
<%
RS.MoveNext
loop
%>

Hope you get the idea..
0
 
LVL 3

Expert Comment

by:etain
ID: 9891468
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.Connection")
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:\myspace\ftz12\tn86721\cashcom.ca\db\appointment_dates.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","March","April","May","June","July","August","September","October","November","December"];
var daycounts = [31,28,31,30,31,30,31,31,30,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>
0
 
LVL 3

Expert Comment

by:xiong8086
ID: 9894616
i think your code sequences must have some change, and in your code [<%=Session("Event")%>"Appointment"], 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
0
 
LVL 3

Expert Comment

by:xiong8086
ID: 9894633
after that, i think you can define your new array appointment size with the property recordset.recordcount.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question