...

View Full Version : Auto fill menu from db??



mikebyrne
12-15-2007, 04:57 PM
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




<!-- #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>

SouthwaterDave
12-23-2007, 03:24 PM
Here are 2 possible solutions:

Accept the user's selection as a postback and then redirect to a new page to display the table.
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum