+ Reply to Thread
Page 1 of 5 1 2 3 ... LastLast
Results 1 to 10 of 43

Thread: Need help with a looping function call in Java + ASP

  1. #1
    Barn Newbie MaxxMills84 is an unknown quantity at this point MaxxMills84's Avatar
    Join Date
    Jun 2009
    Posts
    46
    Rep Power
    3

    Need help with a looping function call in Java + ASP

    Hi everyone. Maybe someone could help me out with this problem.

    I'm trying to use a javascript animated collapse function from dynamicdrive.com embedded into an asp page that is being used as an agenda for a conference.

    The asp page populates its content with data from an external database.

    My problem is that the dynamic drive javascript needs to be "primed" in the html head section with the names of all of the DIVs that will be collapsible in the code below. However, since the sessions of the conference are coming from a database, their number is not fixed. So, I need a way to loop the primer statement the same number of times as the number of sessions.

    Here is the primer code:
    Code:
    animatedcollapse.addDiv('DIVx', 'fade=0')
    
    I basically want the code to loop that line While (NOT Recordset4.EOF) and add Recordset2.Fields.Item("SessionsID").Value where the "x" is in DIVx

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Could you post the whole page code including the JS function?

    We can get a better idea of the context in which it's being used then.

  3. #3
    Barn Newbie MaxxMills84 is an unknown quantity at this point MaxxMills84's Avatar
    Join Date
    Jun 2009
    Posts
    46
    Rep Power
    3

    Here you go:
    HTML Code:
    <script type="text/javascript">
    
    animatedcollapse.addDiv('d1sd', 'fade=0')
    animatedcollapse.addDiv('d1sd1', 'fade=0')
    
    animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
    	//$: Access to jQuery
    	//divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID
    	//state: "block" or "none", depending on state
    }
    
    animatedcollapse.init()
    
    </script>
    
    ....
    
    <body>
    
    <div align="center" class="table">
    
      <table width="575" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td colspan="3" class="rowBGcolor" align="left"><%=formatDateTime((Recordset2.Fields.Item("SessionStartDate").Value), vblongdate)%></td>
        </tr>
        <% 
    While ((Repeat2__numRows <> 0) AND (NOT Recordset2.EOF)) 
    %>
          <tr valign="top" class="GreenRowBGcolor">
            <td align="left"><%=fixTime(FormatDateTime((Recordset2.Fields.Item("Session StartTime").Value), vblongTime))%> - <%=fixTime(FormatDateTime((Recordset2.Fields.Item("SessionEndTime").Value), vbLongTime))%>&nbsp;&nbsp;&nbsp;&nbsp; </td>
            <td align="left"><%=(Recordset2.Fields.Item("SessionTitle").Value)%> </td>
            <td align="right"><a href="symposium2010/downloads/hotelFloorPlan.pdf" target="_blank"><%=(Recordset2.Fields.Item("LocationRoomName").Value)%></a></td>
          </tr>
          
          
          <tr><td colspan="3" align="left"><% If (Recordset2.Fields.Item("SessionDescription").Value <> "") Then %>
            
              <a href="javascript:animatedcollapse.toggle('d1sd')" target="_top">Session Description
            
              </a>
    </td>         
          <% End If %></tr>
          <tr id="d1sd" style="display:none"><td><%= (Recordset2.Fields.Item("SessionDescription").Value) %></td></tr>
        <tr>
    
          <td colspan="3" align="left"><% If (Recordset2.Fields.Item("Full Name (Last, First Middle)").Value <> "")  Then %>
            (moderator:)&nbsp;&nbsp; <%=(Recordset2.Fields.Item("Full Name (Last, First Middle)").Value)%>,&nbsp;<%=(Recordset2.Fields.Item("Expr4").Value)%>,&nbsp;<%=(Recordset2.Fields.Item("Expr5").Value)%><span class="alignRight"> </span></td>
          <% Else %>
          <% End If %>
        </tr>
    	<%
    FilterParam = Recordset2.Fields.Item("SessionsID").Value
    Recordset4.Filter = "SessionsID = " & FilterParam 
    While (NOT Recordset4.EOF)
    %> 
    <tr>
    <td colspan="3" align="left"><% If (Recordset4.Fields.Item("First Name") <> "") Then %>
      <ul>
    <li>
    <strong><%=(Recordset4.Fields.Item("First Name").Value)%>&nbsp; 
            
            <% If (Recordset4.Fields.Item("Middle Name") <> "") Then %>
            <%=(Recordset4.Fields.Item("Middle Name").Value)%>
            <% Else %>
            <% End If %>
    
    
            &nbsp;<%=(Recordset4.Fields.Item("Last Name").Value)%></strong>, &nbsp;<%=(Recordset4.Fields.Item("Job Title").Value)%>,&nbsp;<%=(Recordset4.Fields.Item("Company/Organization").Value)%> </li></ul></td>
    <% End If %>
        </tr>
      
        <tr align="left">
          <td colspan="3">&nbsp; <em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="abstract_detail.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "AssignmentID=" & Recordset4.Fields.Item("SpkrAssgnID").Value %>"><% If (Recordset4.Fields.Item("Ab1AssgnPresMeth")<>"") Then %><%=(Recordset4.Fields.Item("ab1_Titlea").Value)%> <% Else %><%=(Recordset4.Fields.Item("ab2_Titlea").Value)%><% End If %></a></em> </td>
    
    <% 
    Recordset4.MoveNext()
    Wend
    %> 
    </tr>
    <tr>
    <td colspan="3" align="right"><% If (Recordset2.Fields.Item("SponsorName") <> "") Then %>Sponsored By:&nbsp;&nbsp;
      <a href="http://<%=(Recordset2.Fields.Item("website").Value)%>" target="_blank"><%=(Recordset2.Fields.Item("SponsorName").Value)%></a>
      <% End If %></td>
    </tr>
          <% 
      Repeat2__index=Repeat2__index+1
      Repeat2__numRows=Repeat2__numRows-1
      Recordset2.MoveNext()
    Wend
    %>
        <tr>
          <td colspan="3" class="rowBGcolor" align="left"><%=formatDateTime((Recordset1.Fields.Item("SessionStartDate").Value), vblongdate)%> </td>
        </tr>
    	<% 
    While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) 
    %>
    <tr valign="top" class="GreenRowBGcolor">
      
    <td width="190" rowspan="" align="left"><%=fixTime(FormatDateTime((Recordset1.Fields.Item("Session StartTime").Value), vblongTime))%> - <%=fixTime(FormatDateTime((Recordset1.Fields.Item("SessionEndTime").Value), vbLongTime))%> </td>
          <td width="380" align="left"><%=(Recordset1.Fields.Item("SessionTitle").Value)%> </td>
          <td width="190" class="alignRight"><a href="symposium2010/downloads/hotelFloorPlan.pdf" target="_blank"><%=(Recordset1.Fields.Item("LocationRoomName").Value)%></a>&nbsp;&nbsp;&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3" align="left"><% If (Recordset1.Fields.Item("Full Name (Last, First Middle)").Value <> "")  Then %>
            (moderator:)&nbsp;&nbsp; <%=(Recordset1.Fields.Item("Full Name (Last, First Middle)").Value)%>,&nbsp;<%=(Recordset1.Fields.Item("Expr4").Value)%>,&nbsp;<%=(Recordset1.Fields.Item("Expr5").Value)%><span class="alignRight"> </span></td>
          <% Else %>
          <% End If %>
        </tr>
       
        <tr align="left">
          <td colspan="3" ><% If (Recordset1.Fields.Item("SessionDescription").Value <> "") Then %><a href="javascript:animatedcollapse.toggle('d1sd1')" target="_top">Session Description</a> </td>
        <% End If %>
        </tr> 	
        <tr id="d1sd1" style="display:none"><td><%= (Recordset1.Fields.Item("SessionDescription").Value) %></td></tr> 
    	<%
    FilterParam = Recordset1.Fields.Item("SessionsID").Value
    Recordset3.Filter = "SessionsID = " & FilterParam 
    While (NOT Recordset3.EOF)
    %> 
    <tr>
    <td colspan="3" align="left">
    	  	  <% If (Recordset3.Fields.Item("First Name") <> "") Then %>
    <ul>
    <li>
    <strong><%=(Recordset3.Fields.Item("First Name").Value)%>&nbsp; 
            
            <% If (Recordset3.Fields.Item("Middle Name") <> "") Then %>
            <%=(Recordset3.Fields.Item("Middle Name").Value)%>
            <% Else %>
            <% End If %>
    
    
            &nbsp;<%=(Recordset3.Fields.Item("Last Name").Value)%></strong>, &nbsp;<%=(Recordset3.Fields.Item("Job Title").Value)%>,&nbsp;<%=(Recordset3.Fields.Item("Company/Organization").Value)%> </li></ul></td>
    <% End If %>
        </tr>
        <tr align="left">
          <td colspan="3">&nbsp; <em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="abstract_detail.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "AssignmentID=" & Recordset3.Fields.Item("SpkrAssgnID").Value %>">
            <% If (Recordset3.Fields.Item("Ab1AssgnPresMeth")<>"") Then %><%=(Recordset3.Fields.Item("ab1_Titlea").Value)%>
            <% Else %>
            <%=(Recordset3.Fields.Item("ab2_Titlea").Value)%>
            <% End If %>
            </a></em> </td>
    
    <% 
    Recordset3.MoveNext()
    Wend
    %> </tr>
    <tr>
    <td colspan="3" align="right"><% If (Recordset1.Fields.Item("SponsorName") <> "") Then %>Sponsored By:&nbsp;&nbsp;<a href="http://<%=(Recordset1.Fields.Item("website").Value)%>"><%=(Recordset1.Fields.Item("SponsorName").Value)%></a> 
      <% End If %></td>
    </tr>
    <% 
      Repeat1__index=Repeat1__index+1
      Repeat1__numRows=Repeat1__numRows-1
      Recordset1.MoveNext()
    Wend
    %>
         <tr>
          <td colspan="3" class="rowBGcolor" align="left"><%=formatDateTime((Recordset5.Fields.Item("SessionStartDate").Value), vblongdate)%> </td>
        </tr>   
      <% 
    While ((Repeat3__numRows <> 0) AND (NOT Recordset5.EOF)) 
    %>
    
    <tr valign="top" class="GreenRowBGcolor">
    
    <td width="190" rowspan="" align="left"><%=fixTime(FormatDateTime((Recordset5.Fields.Item("Session StartTime").Value), vblongTime))%> - <%=fixTime(FormatDateTime((Recordset5.Fields.Item("SessionEndTime").Value), vbLongTime))%> </td>
          <td width="380" align="left"><%=(Recordset5.Fields.Item("SessionTitle").Value)%> </td>
          <td width="190" class="alignRight"><a href="symposium2010/downloads/hotelFloorPlan.pdf" target="_blank"><%=(Recordset5.Fields.Item("LocationRoomName").Value)%></a>&nbsp;&nbsp;&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3" align="left"><% If (Recordset5.Fields.Item("Full Name (Last, First Middle)").Value <> "")  Then %>
            (moderator:)&nbsp;&nbsp; <%=(Recordset5.Fields.Item("Full Name (Last, First Middle)").Value)%>,&nbsp;<%=(Recordset5.Fields.Item("Expr4").Value)%>,&nbsp;<%=(Recordset5.Fields.Item("Expr5").Value)%><span class="alignRight"> </span></td>
          <% Else %>
          <% End If %>
        </tr>
       
        <tr align="left">
          <td colspan="3" ><% If (Recordset5.Fields.Item("SessionDescription").Value <> "") Then %><a href="session_descriptions.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "SessionsID=" & Recordset5.Fields.Item("SessionsID").Value %>">Session Description</a> </td>
        <% End If %>
        </tr> 
        	 
    	<%
    FilterParam = Recordset5.Fields.Item("SessionsID").Value
    Recordset6.Filter = "SessionsID = " & FilterParam 
    While (NOT Recordset6.EOF)
    %> 
    
        <tr>
    <td colspan="3" align="left">
    	  	  <% If (Recordset6.Fields.Item("First Name") <> "") Then %>
    <ul>
    <li>
    <strong><%=(Recordset6.Fields.Item("First Name").Value)%>&nbsp; 
            
            <% If (Recordset6.Fields.Item("Middle Name") <> "") Then %>
            <%=(Recordset6.Fields.Item("Middle Name").Value)%>
            <% Else %>
            <% End If %>
    
    
            &nbsp;<%=(Recordset6.Fields.Item("Last Name").Value)%></strong>, &nbsp;<%=(Recordset6.Fields.Item("Job Title").Value)%>,&nbsp;<%=(Recordset6.Fields.Item("Company/Organization").Value)%> </li></ul></td>
    <% End If %>
        </tr>
        <tr align="left">
          <td colspan="3">&nbsp; <em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="abstract_detail.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "AssignmentID=" & Recordset6.Fields.Item("SpkrAssgnID").Value %>"><% If (Recordset6.Fields.Item("Ab1AssgnPresMeth")<>"") Then %><%=(Recordset6.Fields.Item("ab1_Titlea").Value)%> <% Else %><%=(Recordset6.Fields.Item("ab2_Titlea").Value)%><% End If %></a></em> </td>
    
    <% 
    Recordset6.MoveNext()
    Wend
    %> </tr>
    <tr>
    <td colspan="3" align="right"><% If (Recordset5.Fields.Item("SponsorName") <> "") Then %>Sponsored By:&nbsp;&nbsp;<a href="http://<%=(Recordset5.Fields.Item("website").Value)%>"><%=(Recordset5.Fields.Item("SponsorName").Value)%></a> 
      <% End If %></td>
    </tr><% 
      Repeat3__index=Repeat3__index+1
      Repeat3__numRows=Repeat3__numRows-1
      Recordset5.MoveNext()
    Wend
    %>
    
      </table>
      
    </div>
    
    </body> 

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    OK. That's slightly confusing because neither of the elements you've used as an example, d1sd and d1sd1, seem to be inside the recordset4 loop and both the elements have a static ID.

    Based on what I think you're trying to do, I've come up with this idea. Not sure if it's the easiest way to achieve it, or if it will work, but I think it should...
    In the head section have something like this:-
    Code:
    <head>
    <script type="text/javascript">
    //global array obj to hold the list of divs
    var divList = new Array();
    //global increment variable to add to the array
    var x = 0;
    //function to call onload to initiate each div
    function initList()
    {
       for(var i=0;i<divList.length;i++)
       {
            animatedcollapse.addDiv(divList[i],'fade=0');
       }
    }       
    </script>
    </head>
    
    Add this to the body tag
    Code:
    <body onload="initList();">
    
    Within your page code and inside the loop where you create each element, include this:-
    Code:
    <%
    response.write("<script type=""text/javascript"">")
    response.write("divList[x] ='" &  Recordset2.Fields.Item("SessionsID").Value & "';")
    response.write("x++;")
    response.write("</script>")
    %>
    
    I've written it as ASP code as I presume it will be inside your loop.

    I'm not sure if this will work when writing out the JS code to add to each array dynamically.

    The alternative might be to generate the array index on the server side so you'd have something like
    Code:
    <%
    Dim x
    x = 0
    %>
    .
    .
    <%
    response.write("<script type=""text/javascript"">")
    response.write("divList[" & x & "] ='" &  Recordset2.Fields.Item("SessionsID").Value & "';")
    response.write("</script>")
    .
    .
    .
    x = x+1
    recordset2.movenext
    wend
    
    I think either of these should work. The basic principle is that the page will be created on the server side, rendered to the browser when the client side array will be populated. Once the page has loaded, the OnLoad function will be called that loops through the JS array and initiates the collapse function for each element.

    Hope that makes sense.

  5. #5
    Barn Newbie MaxxMills84 is an unknown quantity at this point MaxxMills84's Avatar
    Join Date
    Jun 2009
    Posts
    46
    Rep Power
    3

    Ya, I forgot to mention that it doesn't use variable div's in the recordset loop, as I hadn't got that far yet before I realized that I didn't know how to initialize them in the javascript headers.

    thanks so much for your help. I'll give it a shot tomorrow and let you know how it works out...

  6. #6
    Barn Newbie MaxxMills84 is an unknown quantity at this point MaxxMills84's Avatar
    Join Date
    Jun 2009
    Posts
    46
    Rep Power
    3

    so, the actual name of the DIV will be equal to the sessionsID.value?

    Will I make the description collapse like so:
    HTML Code:
     <% 
    While ((Repeat2__numRows <> 0) AND (NOT Recordset2.EOF)) 
    %>
          <tr valign="top" class="GreenRowBGcolor">
            <td align="left"><%=fixTime(FormatDateTime((Recordset2.Fields.Item("Session StartTime").Value), vblongTime))%> - <%=fixTime(FormatDateTime((Recordset2.Fields.Item("SessionEndTime").Value), vbLongTime))%>&nbsp;&nbsp;&nbsp;&nbsp; </td>
            <td align="left"><%=(Recordset2.Fields.Item("SessionTitle").Value)%> </td>
            <td align="right"><a href="symposium2010/downloads/hotelFloorPlan.pdf" target="_blank"><%=(Recordset2.Fields.Item("LocationRoomName").Value)%></a></td>
          </tr>
                
          <tr><td colspan="3" align="left"><% If (Recordset2.Fields.Item("SessionDescription").Value <> "") Then %>
            <%
    			response.write("<script type=""text/javascript"">")
    			response.write("divList[x] ='" &  Recordset2.Fields.Item("SessionsID").Value & "';")
    			response.write("x++;")
    			response.write("</script>")
    			
              	response.write("<a href=""javascript:animatedcollapse.toggle('" & Recordset2.Fields.Item("SessionsID").Value & "')"" target=""_top"">Session Description</a>") 
    		%>
    </td>         
          <% End If %></tr>
          <%
    	  response.write("<tr id=" & Recordset2.Fields.Item("SessionsID").Value & " style=""display:none"">")
    	  %>
          <td><%= (Recordset2.Fields.Item("SessionDescription").Value) %></td></tr>
        <tr>
    
          <td colspan="3" align="left"><% If (Recordset2.Fields.Item("Full Name (Last, First Middle)").Value <> "")  Then %>
            (moderator:)&nbsp;&nbsp; <%=(Recordset2.Fields.Item("Full Name (Last, First Middle)").Value)%>,&nbsp;<%=(Recordset2.Fields.Item("Expr4").Value)%>,&nbsp;<%=(Recordset2.Fields.Item("Expr5").Value)%><span class="alignRight"> </span></td>
          <% Else %>
          <% End If %>
        </tr> 
    Last edited by MaxxMills84; October 5th, 2009 at 12:30 PM.

  7. #7
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by MaxxMills84
    so, the actual name of the DIV will be equal to the sessionsID.value?
    Yes. That's what you were after, wasn't it?

    That looks about right, apart from I think you're missing a closing bracket on:-
    Code:
    response.write("<tr id=" & Recordset2.Fields.Item("SessionsID").Value & " style=""display:none"">")
     

  8. #8
    Barn Newbie MaxxMills84 is an unknown quantity at this point MaxxMills84's Avatar
    Join Date
    Jun 2009
    Posts
    46
    Rep Power
    3

    okay, so i forgot to mention that the sessionsIDs are not sequential.

    i think this code would work if the sessions were being read sequentially by id, but that is not the case.

    otherwise, could the acutal sessionsID numerical variable be passed to the java function and have it just load those divs?

    I'm going to take a stab at it, but if I can't get it to work, I think I'm just going to have the animated collapse code initialize something like 100 divs automatically, and see if I can make it work from there.

  9. #9
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    It shouldn't make any difference what the values are. All it does is pass the value to a Javascript Array. Once the page loads, the initialise function is called (<body onload= ) that pulls each value from the array and initialises it with the animated collapse function.

  10. #10
    Barn Newbie MaxxMills84 is an unknown quantity at this point MaxxMills84's Avatar
    Join Date
    Jun 2009
    Posts
    46
    Rep Power
    3

    Well, it's behaving as if the divs haven't been initialized.

    Maybe I'm loading the divs into the array in the wrong place.

+ Reply to Thread
Page 1 of 5 1 2 3 ... LastLast

Similar Threads

  1. How to call a .js file in my form?
    By dtz in forum JavaScript Programming
    Replies: 9
    Last Post: July 28th, 2009, 07:28 AM
  2. Looping Through Records
    By BLaaaaaaaaaarche in forum ASP Development
    Replies: 3
    Last Post: July 15th, 2009, 09:42 PM
  3. Call Serverside Function from A Tag
    By noFriends in forum .NET Development
    Replies: 18
    Last Post: June 29th, 2009, 10:59 AM
  4. Help with JS function
    By Wolffy in forum JavaScript Programming
    Replies: 1
    Last Post: June 9th, 2009, 10:52 AM
  5. Looping through variables.
    By mehere in forum SQL Development
    Replies: 2
    Last Post: June 4th, 2008, 01:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO