Show/Hide Database entry

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skatz25
    New Member
    • May 2010
    • 1

    #1

    Show/Hide Database entry

    Hello,

    I am trying to create a small post forum that via a database, the asp code displays a topic, author, and date submitted. on clicking the post, the messages of the user appears.
    I tried to write a javascript function to perform the show/hide feature. I can make it work with only text
    Code:
    <p class="posthidden" id="showhide">msg: some text</p>
    but not with the database field
    Code:
    <p class="posthidden" id="showhide">msg: <% 'response.write(rs("comments")) %></p>
    I added two bitmaps that show what I am trying to do, any help would be appreciated

    Below is my code:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Update Entry Select</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    
    
    <script type="text/javascript">
    function expandcollapse (postid) {
    whichpost = document.getElementById(postid);
    if (whichpost.className=="postshown") { whichpost.className="posthidden"; }
    else { whichpost.className="postshown"; }
    }
    </script>
    <style type="text/css">
    .posthidden {display:none}
    .postshown {display:inline}
    </style>
    </head>
    
    <body dir="rtl">
    <%
    'Dimension variables
    Dim adoCon 'Holds the Database Connection Object
    Dim rs 'Holds the recordset for the records in the database
    Dim strSQL 'Holds the SQL query for the database
    
    'Create an ADO connection odject
    Set adoCon = Server.CreateObject("ADODB.Connection")
    
    'Set an active connection to the Connection object using a DSN-less connection
    adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("forum.mdb")
    
    'Set an active connection to the Connection object using DSN connection
    'adoCon.Open "DSN=forum"
    
    'Create an ADO recordset object
    Set rs = Server.CreateObject("ADODB.Recordset")
    
    'Initialise the strSQL variable with an SQL statement to query the database
    strSQL = "SELECT * FROM FORUM_MESSAGES;"
    
    'Open the recordset with the SQL query
    rs.Open strSQL, adoCon
    
    %>
    <table>
       <tr>
         <td>
         <p style="width: 330px">Topic</p>
         </td>
         <td>
         <p style="width: 274px">Author</p>
         </td>
         <td style="width: 271px">
         <p>Date</p>
         </td>
       </tr>
       <%
       'Loop through the recordset
    Do While not rs.EOF
    %>
       <tr>
         <td>
           <a href="javascript:expandcollapse('showhide')"><% response.write(rs("Topic")) %></a>
           <p class="posthidden" id="showhide">msg: <% 'response.write(rs("comments")) %></p>
          </td>
    	  <td>
    	   <% response.write(rs("AuthorName")) %>
    	  </td>
    	  <td style="width: 271px">
    	   <% response.write(rs("LastThreadPost")) %>
    	  </td>
    	</tr>
    
    <%
    'Move to the next record in the recordset
    rs.MoveNext
    Loop
    %>
    </table>
    </body>
    </html>
    Attached Files
    Last edited by jhardman; May 6 '10, 04:57 AM. Reason: put your code in code tags. please use the code tag button - # - next time
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    what does the resulted html code look like? the answer has to be there.

    Jared

    Comment

    Working...