Forums
This topic is locked
Database - Use checkboxes to select fields in resu
Posted 08 Sep 2002 22:04:13
1
has voted
08 Sep 2002 22:04:13 alison mcl posted:
Hi I've searched all round the web for an answer to this before posting and have found quite a few people asking the question but never any answer to it. I'm using asp but any assistance for any language could help start me in the right direction.
I've got a webpage where I would like the user to select checkboxes that they would then submit and on the results page be able to view only those fields/columns they have opted to view. (i.e. the checkboxes relate to the columns they would see).
I know this is the opposite way round and normally you search for criteria in records but I just can't think of a way round this to get it to work. The fields themselves have just numbers in them so there are no distinct features between the fields.
Am I approaching it from the wrong angle (I just have one table with the fields and records) and is it possible?
Any help VERY much appreciated as my brain feels like its junked and my nails are a bit worse for wear!
cheers
B
Replies
Replied 09 Sep 2002 13:03:51
09 Sep 2002 13:03:51 Andrew Watson replied:
You should be able to achieve this with conditional regions....
your form should loop through all items in the recordset returning a checkbox called the fieldname.
now when submitted you should have form data that says which was checked.
Then just create a layout for ALL columns and then for each column put it in a conditional region ie only show this column if it exists in the form data.
if i can get a little time today ill pop up some sample code....
cheers
LEED
:: Son, im Thirty.... ::
your form should loop through all items in the recordset returning a checkbox called the fieldname.
now when submitted you should have form data that says which was checked.
Then just create a layout for ALL columns and then for each column put it in a conditional region ie only show this column if it exists in the form data.
if i can get a little time today ill pop up some sample code....
cheers
LEED
:: Son, im Thirty.... ::
Replied 09 Sep 2002 13:36:08
09 Sep 2002 13:36:08 Andrew Watson replied:
This is one way of doing it, not the best but it should get you started. not the most dynamic way but it will work.
<font color=red>FORM PAGE</font id=red>
<pre id=code><font face=courier size=2 id=code>
<!--#include file="Connections/Test.asp" -->
<%
set rsColumns = Server.CreateObject("ADODB.Recordset"
rsColumns.ActiveConnection = MM_Test_STRING
rsColumns.Source = "SELECT * FROM MyTable"
rsColumns.CursorType = 0
rsColumns.CursorLocation = 2
rsColumns.LockType = 3
rsColumns.Open()
rsColumns_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="ViewColumns.asp">
<Table>
<% for each f in rsColumns.Fields %>
<tr><td>
<input type="checkbox" name="<%= (f.Name) %>" value="show">
</td><td>
<%= (f.Name) %>
</td></tr>
<% next %>
</Table>
<br>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
<%
rsColumns.Close
%>
</font id=code></pre id=code>
<font color=red>TABLE PAGE</font id=red>
<pre id=code><font face=courier size=2 id=code>
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/Test.asp" -->
<%
set rsColumns = Server.CreateObject("ADODB.Recordset"
rsColumns.ActiveConnection = MM_Test_STRING
rsColumns.Source = "SELECT * FROM MyTable"
rsColumns.CursorType = 0
rsColumns.CursorLocation = 2
rsColumns.LockType = 3
rsColumns.Open()
rsColumns_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<% If Request.Form("Column1" = "show" Then %>
<td>Col 1</td>
<% End If %>
<% If Request.Form("Column2" = "show" Then %>
<td>Col 2</td>
<% End If %>
<% If Request.Form("Column3" = "show" Then %>
<td>Col 3</td>
<% End If %>
<% If Request.Form("Column4" = "show" Then %>
<td>Col 4</td>
<% End If %>
<% If Request.Form("Column5" = "show" Then %>
<td>Col 5</td>
<% End If %>
<% If Request.Form("Column6" = "show" Then %>
<td>Col 6</td>
<% End If %>
</tr>
<% While Not rsColumns.EOF %>
<tr>
<% If Request.Form("Column1" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column1".Value)%></td>
<% End If %>
<% If Request.Form("Column2" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column2".Value)%></td>
<% End If %>
<% If Request.Form("Column3" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column3".Value)%></td>
<% End If %>
<% If Request.Form("Column4" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column4".Value)%></td>
<% End If %>
<% If Request.Form("Column5" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column5".Value)%></td>
<% End If %>
<% If Request.Form("Column6" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column6".Value)%></td>
<% End If %>
</tr>
<% rsColumns.Movenext
Wend
%>
</table>
</body>
</html>
<%
rsColumns.Close()
%>
</font id=code></pre id=code>
:: Son, im Thirty.... ::
<font color=red>FORM PAGE</font id=red>
<pre id=code><font face=courier size=2 id=code>
<!--#include file="Connections/Test.asp" -->
<%
set rsColumns = Server.CreateObject("ADODB.Recordset"
rsColumns.ActiveConnection = MM_Test_STRING
rsColumns.Source = "SELECT * FROM MyTable"
rsColumns.CursorType = 0
rsColumns.CursorLocation = 2
rsColumns.LockType = 3
rsColumns.Open()
rsColumns_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="ViewColumns.asp">
<Table>
<% for each f in rsColumns.Fields %>
<tr><td>
<input type="checkbox" name="<%= (f.Name) %>" value="show">
</td><td>
<%= (f.Name) %>
</td></tr>
<% next %>
</Table>
<br>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
<%
rsColumns.Close
%>
</font id=code></pre id=code>
<font color=red>TABLE PAGE</font id=red>
<pre id=code><font face=courier size=2 id=code>
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/Test.asp" -->
<%
set rsColumns = Server.CreateObject("ADODB.Recordset"
rsColumns.ActiveConnection = MM_Test_STRING
rsColumns.Source = "SELECT * FROM MyTable"
rsColumns.CursorType = 0
rsColumns.CursorLocation = 2
rsColumns.LockType = 3
rsColumns.Open()
rsColumns_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<% If Request.Form("Column1" = "show" Then %>
<td>Col 1</td>
<% End If %>
<% If Request.Form("Column2" = "show" Then %>
<td>Col 2</td>
<% End If %>
<% If Request.Form("Column3" = "show" Then %>
<td>Col 3</td>
<% End If %>
<% If Request.Form("Column4" = "show" Then %>
<td>Col 4</td>
<% End If %>
<% If Request.Form("Column5" = "show" Then %>
<td>Col 5</td>
<% End If %>
<% If Request.Form("Column6" = "show" Then %>
<td>Col 6</td>
<% End If %>
</tr>
<% While Not rsColumns.EOF %>
<tr>
<% If Request.Form("Column1" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column1".Value)%></td>
<% End If %>
<% If Request.Form("Column2" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column2".Value)%></td>
<% End If %>
<% If Request.Form("Column3" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column3".Value)%></td>
<% End If %>
<% If Request.Form("Column4" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column4".Value)%></td>
<% End If %>
<% If Request.Form("Column5" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column5".Value)%></td>
<% End If %>
<% If Request.Form("Column6" = "show" Then %>
<td><%=(rsColumns.Fields.Item("Column6".Value)%></td>
<% End If %>
</tr>
<% rsColumns.Movenext
Wend
%>
</table>
</body>
</html>
<%
rsColumns.Close()
%>
</font id=code></pre id=code>
:: Son, im Thirty.... ::