Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    48
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Auto fill menu from db??

    Is it possible to autofill my menu with the pnum fields and depending on the user selection show the table below.

    At the moment my table just displays all records

    Code:
    <!-- #include file="connection.asp" -->
    <%
    ' Dim variables
    Dim strSQL, objRS
    
    Sub showProjects
    	strSQL = "SELECT PNUMBER, PNAME, PLOCATION, DNUM FROM Project"
    	Set objRS = siteConn.Execute(strSQL)
    
    	If Not objRS.EOF Then
    		Do While Not objRS.EOF
    			response.write Space(4) & "<tr>" & vbCrLf
    			response.write Space(6) & "<td>" & objRS("PNUMBER") & "</td>" & vbCrLf
    			response.write Space(6) & "<td>" & objRS("PNAME") & "</td>" & vbCrLf
    			response.write Space(6) & "<td>" & objRS("PLOCATION") & "</td>" & vbCrLf
    			response.write Space(6) & "<td>" & objRS("DNUM") & "</td>" & vbCrLf
    			response.write Space(6) & "<td><a href=""editProject.asp?pNumber=" & objRS("PNUMBER") & """>Edit</a> | <a href=""deleteProject.asp?pNumber=" & objRS("PNUMBER") & """ onclick=""return confirmDelete()"">Delete</a></td>" & vbCrLf
    			response.write Space(4) & "</tr>" & vbCrLf
    		objRS.MoveNext
    		Loop
    	Else
    		response.write Space(4) & "<tr>" & vbCrLf
    		response.write Space(6) & "<td colspan=""5"">Sorry, currently no available projects.</td>" & vbCrLf
    		response.write Space(4) & "</tr>" & vbCrLf
    	End If
    
    	objRS.Close
    End Sub
    %>
    <html>
    <head>
    <script type="text/javascript">
    <!-- Hide the script from old browsers --
    function confirmDelete() {
    	var deleteRecord = confirm("Are you sure you want to delete this record?");
    	if (deleteRecord)
    		return true ;
    	else
    		return false ;
    }
    //-->
    </script>
    <style type="text/css">
    <!--
    .style1 {
    	font-size: 10mm;
    	font-weight: bold;
    }
    -->
    </style>
    </head>
    <head>
    <title>Displaying Records: Projects Database</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
    <body bgcolor="#FFFF00">
    <p align="center" class="style1">Database Maintenance System
    <p align="center">Please select project number from the menu or Add new project button:</p>
    <form name="form1" method="post" action="">
      <label>
      <div align="center">
        <select name="Menuoption" size="1" id="Menuoption">
        </select>
      </div>
      </label>
    </form>
    <form action="" method="post" name="" id="">
      <label>
      <div align="center">
        <input type="submit" name="Add User" id="Add User" value="Add User">
      </div>
      </label>
    </form>
    <div align="center">
      <table width="600" border="1" cellspacing="2" cellpadding="0">
        <tr>
          <td><b>Project Number</b></td>
          <td><b>Project Name</b></td>
          <td><b>Project Location</b></td>
          <td><b>Department Number</b></td>
          <td><b>Action</b></td>
          </tr>
      <% Call showProjects %>
        <tr>
          <td colspan="4">&nbsp;</td>
          </tr>
        </table>
      </p>
    </div>
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    May 2007
    Location
    UK
    Posts
    180
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Here are 2 possible solutions:
    1. Accept the user's selection as a postback and then redirect to a new page to display the table.
    2. Use AJAX to dynamically rebuild the table. Basically you would need some JavaScript to handle the user's selection. It would build a new XMLHttpRequest object, call the send method for another page. This page would return the table and the JavaScript code in your original page would use the response to rebuild the table.


  •  

    Posting Permissions

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