Browse DevX
Sign up for e-mail newsletters from DevX


Form-Building Routines III—the Conclusion  : Page 3

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

The Code Explained
The initial lines of code for the DisplayRadioButtonFromArray routine are identical to the DisplayTextbox routine. The routine displays two cells of a single row of a table, with the label on the left side.

      Response.Write "<TR>"
      Response.write "<TD ALIGN=""RIGHT"" _
      If blnRequired Then
         Response.write "<FONT COLOR=""BLUE"">"
      End if
      Response.Write strLabel & "&nbsp;</FONT></TD>"
      Response.Write "<TD ALIGN=""LEFT"" VALIGN=""TOP"">"
Next, the code outputs the HTML for a group of radio buttons, using the array values passed to in the fourth (aryLabels) parameter to set the captions. You can use the VBScript function UBound to discover the maximum index of the array:

   For i = 0 to UBound(aryLabels)
For each item in the array, the loop writes the INPUT tag that produces the radio button and then writes the caption using the text in the array item.

      Response.Write "<INPUT TYPE=""RADIO"" " & _
         " NAME=""" & strFieldName & """ " & _
         " VALUE=""" & i & """>" & _
         aryLabels(i) & _
Add a HTML line break
tag and continue with the next item in the array:

Finally, close the table cell and table row tags:

   Response.Write "</TD>"
   Response.Write "</TR>"
Notice the parameters to this subroutine:

   DisplayRadioButtonFromArray   "Gender:","gender",_
The subroutine expects an array of captions. You can generate the array using the VBScript "Array" function, which returns an array from a comma-separated list of values. Alternatively, you can create an array variable, assign individual elements to the array and pass the array variable as the argument to the subroutine call.

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