Browse DevX
Sign up for e-mail newsletters from DevX


Form-Building Routines III—the Conclusion  : Page 2

Use automatic control-building routines to create and populate checkbox and radio button controls from a database.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Simple Radio Buttons and Check Boxes
For simple radio buttons and checkboxes, such as gender or yes/no questions, you generally hard-coded the captions rather than populating them from a database. . Here's the code to generate simple radio buttons and checkboxes, like those shown in Figure 1.:

      WriteFormBegin    "frmInfo", "pgApply.asp", _
         "POST", "return ValidateForm(this);"
      WriteTableBegin 600
      DisplayTextField    "First Name:", "first_name", _
         "first_name", 60, 35, True
      DisplayTextField    "Last Name:", "last_name", _
         "last_name", 60, 35, True
      DisplayTextField    "Title:", "title", _
         "title", 60, 80, False
      DisplayRadioButtonFromArray   "Gender:","gender",_
      DisplayCheckBox      "Preferences:","notify_me",_
         1, "Notify me via e-mail"
      DisplaySubmitButton  "Submit", "cmd"
The new code is the call to the "DisplayRadioButtonFromArray" sub routine. For the "gender" group, you write:

   DisplayRadioButtonFromArray   "Gender:","gender",_
The code to display the checkbox using the new "DisplayCheckBox" routine is similar:

   DisplayCheckBox      "Preferences:","notify_me",_
      1, "Notify me via e-mail"
The DisplayRadioButtonFromArray routine accepts 5 parameters, of which the fourth is the most interesting (see Table 1).

Table 1: Parameters for the DisplayRadioButtonFromArray routine.

StrLabel The text for the label
StrFieldName The name of the radio button group
StrValue The index of the radio button that should be selected by default.
AryLabels An array of captions—one for each radio button in the group.
blnRequired A Boolean flag to indicate this group of radio button is a required control on the form.

I called the routine "DisplayRadioButtonFromArray" because it accepts an array of captions with a default "VALUE" property equal to the index of the array—or some multiple thereof. Here's the code:

   Sub DisplayRadioButtonFromArray   (byval strLabel, byval strFieldName,  _
      byval strValue, byval aryLabels, _
      byval blnRequired)
      Dim i
      Response.Write "<TR>"
      Response.write "<TD ALIGN=""RIGHT"" VALIGN=""TOP"">" 
      If blnRequired Then
         Response.write "<FONT COLOR=""BLUE"">"
      End if
      Response.Write strLabel & "&nbsp;</FONT></TD>"
      Response.Write "<TD ALIGN=""LEFT"" VALIGN=""TOP"">"
      For i = 0 to UBound(aryLabels)
         Response.Write "<INPUT TYPE=""RADIO"" " & _
      " NAME=""" & strFieldName & """ " & _
      " VALUE=""" & i & """>" & _
      aryLabels(i) & _
      Response.Write "</TD>"
      Response.Write "</TR>"
   End Sub

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date