Dec 3rd, 2000, 02:51 PM
Okay, so I have this site where it displays the working directories files with a checkbox for each file. If you check the box and hit "delete" it deletes the file from the server (kinda like geocities file manager). Does anyone know how refferr to each of the CHECKED checkboxes and their names? Here's my code:
Music.asp
<%@ Language="VBScript" %>
<html>
<head>
<%
'Define the File System Object and set variables
'FSO = FileSystemObject
Dim FSO, Folder, FolderContents, FileItem
Set FSO = CreateObject("Scripting.FileSystemObject") 'Create FSO
Set Folder = FSO.GetFolder("C:\muzak\soul") 'Declare folder to have contents displayed
Set FolderContents = Folder.Files
%>
<title><%= Response.Write(Folder.Name) %></title>
<style type="text/css">
body, table {color:#000000; font-family:Verdana; font-size:11px}
</style>
</head>
<body background="/images/bground.gif" bgcolor="#ffffff" text="#000000" marginheight="0" topmargin="0">
<form action="Confirm.asp" method="post">
<table border="0" cellpadding="4" cellspacing="0">
<tr><td bgcolor="darkgray" align=left>
</td><td bgcolor="darkgray" align=left>
<font size="2"><b>File</b></font>
</td><td bgcolor="darkgray" align=left>
<font size="2"><b>Size (mb)</b></font>
</td></tr>
<%
'Display each file's name and size with a checkbox
Response.Write("<font size=5>Contents of: " & Folder & "<p>")
Dim FileSize
For Each FileItem In FolderContents
FileSize = Round(FileItem.Size / 1000000, 1) 'Converts file size into MB, rounds to tenth place
Response.Write("<tr><td bgcolor=lightgrey align=left>")
Response.Write("<input type=checkbox name=" & FileItem.Name & " value=" & FileItem.Name & ">")
Response.Write("</td><td bgcolor=lightgrey align=left>")
Response.Write(FileItem.Name) 'Displays file name
Response.Write("</td><td bgcolor=lightgrey align=right>")
Response.Write(FileSize) 'Displays file size in MB
Response.Write("</td></tr>")
Next
%>
</td></tr>
<tr><td colspan=3>
<input type="submit" value="Delete">
</td></tr>
</table>
</form>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------------
Confirm.asp
<%@ Language="VBScript" %>
<html>
<head>
<title>Warning!</title>
<style type="text/css">
body, table {color:#000000; font-family:Verdana; font-size:11px}
</style>
</head>
<body background="/images/bground.gif" bgcolor="#ffffff" text="#000000" marginheight="0" topmargin="0">
<%
'Extract number of checked files
Dim Checked, FilesToDelete
Checked = 0 'Set number of checked to zero
For Each Checked In Request.Form
thisvalue = Request.Form(Checked)
If thisvalue = "on" Then
FilesToDelete = FilesToDelete + 1
End If
If FilesToDelete > 1 Then
FileNum = "files"
Else
FileNum = "file"
End If
Next
%>
<font color="#ff0000" size="6">Warning!</font><br>
<fotn size="3"><b>Are you sure that you want to delete the following <%= Response.Write(FileNum & "?") %></b></font>
<hr align="left" color="#000000" size="1" width="600" noshade>
<%
'Display all the files checked
Response.Write(thisvalue & "<br>")
%>
<br>
<input type="button" value="No, take me back" onClick="location='Music.asp'">
<input type="button" value="Yes, proceed" onClick="location='Delete.asp'">
</body>
</html>
Music.asp
<%@ Language="VBScript" %>
<html>
<head>
<%
'Define the File System Object and set variables
'FSO = FileSystemObject
Dim FSO, Folder, FolderContents, FileItem
Set FSO = CreateObject("Scripting.FileSystemObject") 'Create FSO
Set Folder = FSO.GetFolder("C:\muzak\soul") 'Declare folder to have contents displayed
Set FolderContents = Folder.Files
%>
<title><%= Response.Write(Folder.Name) %></title>
<style type="text/css">
body, table {color:#000000; font-family:Verdana; font-size:11px}
</style>
</head>
<body background="/images/bground.gif" bgcolor="#ffffff" text="#000000" marginheight="0" topmargin="0">
<form action="Confirm.asp" method="post">
<table border="0" cellpadding="4" cellspacing="0">
<tr><td bgcolor="darkgray" align=left>
</td><td bgcolor="darkgray" align=left>
<font size="2"><b>File</b></font>
</td><td bgcolor="darkgray" align=left>
<font size="2"><b>Size (mb)</b></font>
</td></tr>
<%
'Display each file's name and size with a checkbox
Response.Write("<font size=5>Contents of: " & Folder & "<p>")
Dim FileSize
For Each FileItem In FolderContents
FileSize = Round(FileItem.Size / 1000000, 1) 'Converts file size into MB, rounds to tenth place
Response.Write("<tr><td bgcolor=lightgrey align=left>")
Response.Write("<input type=checkbox name=" & FileItem.Name & " value=" & FileItem.Name & ">")
Response.Write("</td><td bgcolor=lightgrey align=left>")
Response.Write(FileItem.Name) 'Displays file name
Response.Write("</td><td bgcolor=lightgrey align=right>")
Response.Write(FileSize) 'Displays file size in MB
Response.Write("</td></tr>")
Next
%>
</td></tr>
<tr><td colspan=3>
<input type="submit" value="Delete">
</td></tr>
</table>
</form>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------------
Confirm.asp
<%@ Language="VBScript" %>
<html>
<head>
<title>Warning!</title>
<style type="text/css">
body, table {color:#000000; font-family:Verdana; font-size:11px}
</style>
</head>
<body background="/images/bground.gif" bgcolor="#ffffff" text="#000000" marginheight="0" topmargin="0">
<%
'Extract number of checked files
Dim Checked, FilesToDelete
Checked = 0 'Set number of checked to zero
For Each Checked In Request.Form
thisvalue = Request.Form(Checked)
If thisvalue = "on" Then
FilesToDelete = FilesToDelete + 1
End If
If FilesToDelete > 1 Then
FileNum = "files"
Else
FileNum = "file"
End If
Next
%>
<font color="#ff0000" size="6">Warning!</font><br>
<fotn size="3"><b>Are you sure that you want to delete the following <%= Response.Write(FileNum & "?") %></b></font>
<hr align="left" color="#000000" size="1" width="600" noshade>
<%
'Display all the files checked
Response.Write(thisvalue & "<br>")
%>
<br>
<input type="button" value="No, take me back" onClick="location='Music.asp'">
<input type="button" value="Yes, proceed" onClick="location='Delete.asp'">
</body>
</html>