OK. Let's start with this entire page, then you can cut / paste / crop and edit into your own layout once you see it working.
You'll want to start by copying this entire page into a test page and running it. But read the notes below because you need to provide some values before it will work.
Important Notes ..
#1: The submit button calls a JavaScript function that currently does nothing. But you can put validation in this function to prevent submittal on conditional statments.
#2: The
action value in the form tag needs to be set properly to the page that you want to submit the information to.
#3: I figured that with all the data you want to display in the list box for each record, that it could potentially get wider than you want. Therefore, I wrote a little method that allows you to limit the amount of characters displayed for opponents and locations. All you have to do is set the variables.
#4: You must set the
strProvider string to your current connection string or DSN name.
#5: The value of each option is set to the unique id field in your table. We're going to get that value on the next page using the
Request.Form("gamelist"
method and build an SQL query to select that record from the table and populate a form and fields that you can edit, change and update the database with.
#6: You can copy the page directly into an ASP page, including the comments. I should have tagged all of the comments correctly so the page will still run.
#7: Check the field names that I am referencing. Where ever you see
objRSt("somefield"
, make sure the field name is correct.
#8: It's untested .. I won't be surprised if you throw an error or two. If you get stuck, just let me know.
#9: I don't usually spend this much time replying to a post, and I can see that this thread could get very lengthly. You can email me with questions that you don't feel will be helpful to other readers at todd@fuelaccess.com
#10: I'm probably covering some things that you are already familiar with. Feel free to replace any portion of my examples with solutions you already have in place.
<%@ Language=VBScript %>
<% Option Explicit %>
<html>
<head>
<script Language="JavaScript">
<!--
function checkForm(form_ref) {
//ANY VALIDATION FOR THIS FORM CAN GO HERE
}
//-->
</script>
</head>
<body>
<form name="games" method="post" action="nextpage.asp" onSubmit="checkForm(this);">
<%
dim m
dim objRst
dim strProvider
dim strSQL
dim opponent
dim maxoppchars
dim location
dim maxlocchars
'SET MAXIMUM AMOUNT OF CHARACTERS TO DISPLAY IN LISTBOX FOR OPPONENT AND LOCATION
'SET TO 999 TO DISPLAY ALL CHARACTERS
maxoppchars = 10
maxlocchars = 10
strProvider = 'your database connection string or dsn
'CREATE THE RECORDSET
Set objRst = Server.CreateObject("ADODB.recordset"
objRst.CursorLocation = 3
strSQL = "SELECT * FROM games"
objRst.Open strSQL, strProvider
set objRst.ActiveConnection = Nothing
%>
<select size="10" name="gamelist">
<%
IF NOT objRst.EOF THEN
m = " selected "
WHILE NOT objRst.EOF ' LOOP FOR EACH RECORD
opponent = Trim(objRst("opponent"
)
IF Len(opponent) > maxoppchars THEN
opponent = Left(opponent,maxoppchars) & ".."
END IF
location = Trim(objRst("location"
)
IF Len(location) > maxlocchars THEN
location = Left(location,maxlocchars) & ".."
END IF
%>
<option<%=m%>value="<%=objRst("id"
%>"><%=objRst("month"
%>/<%=objRst("day"
%>/<%=objRst("year"
%> - <%=objRst("time"
%> - <%=location%> - <%=opponent%></option>
<%
objRst.MoveNext
m = " "
WEND
ELSE ' IF NO RECORDS ARE FOUND
%>
<option value="">No Records Found ..</option>
<%
END IF
set objRst = Nothing
%>
</select><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
ToddWW
