Rick Curtis - Tutorial 11

Creating Form Elements Dynamically

This is a follow-up to Tutorial 9. In that tutorial I explained how to "mass produce" repetitive ASP code. The key here is to use either repeat regions or Tom Mucks' Horizontal Looper to set up a series of Check Boxes that are directly driven from the database.

  1. Add the recordset
  2. Create the Horizontal Looper
  3. Add a Checkbox
  4. Set the Name of the Checkbox to the recordset value that corresponds to the field name (using the same table scheme as in Tutorial 9).
  5. Voila, a list of Checkboxes dynamically generated from your database.

 

Horizontal Looper Version

<table width="100%">
<%
startrw = 0
endrw = HLooper1__index
numberColumns = 2
numrows = -1
while((numrows <> 0) AND (Not rsSkillsG.EOF))
startrw = endrw + 1
endrw = endrw + numberColumns
%>
<tr align="center" valign="top">
<%
While ((startrw <= endrw) AND (Not rsSkillsG.EOF))
%>
<td>
<div align="left">
<input type="checkbox"
name="<%=(rsSkillsG.Fields.Item("SkillID").Value)%>" value="1">
<%=(rsSkillsG.Fields.Item("Lookup").Value)%> </div>
</td>
<%
startrw = startrw + 1
rsSkillsG.MoveNext()
Wend
%>
</tr>
<%
numrows=numrows-1
Wend
%>
</table>

 

Repeat Region Version

<td width="83%" height="57">
<%
While ((Repeat1__numRows <> 0) AND (NOT rsSkillsD.EOF))
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>

<input type="checkbox" name="<%=(rsSkillsD.Fields.Item("SkillID").Value)%>" value="1">
<%=(rsSkillsD.Fields.Item("Lookup").Value)%> </td>
</tr>
</table>

<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsSkillsD.MoveNext()
Wend
%>

 

Copyright © 2001 All rights reserved Rick Curtis, Princeton, NJ, USA
Macromedia and UltraDev are trademarks of the Macromedia Corporation.