KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Generating items dynamically for an HTML drop-down list
PRODUCT: 4D | VERSION: 6.7 | PLATFORM: Mac & Win
Published On: September 7, 2001
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

If you have a drop-down list in your HTML form and you want to be able to control which group of selectable items will be displayed, you may need to generate the list dynamically. Here is a simple way to generate selectable item in the dropdown list.

The conventional way to create a group of selectable items in a drop-down list:

<SELECT NAME="SelectableList">
<OPTION VALUE="Item 1">Item 1</OPTION>
<OPTION VALUE="Item 2">Item 2</OPTION>
<OPTION VALUE="Item 3">Item 3</OPTION>
</SELECT>

A new way to create a group of selectable items dynamically in a drop-down list:

<SELECT NAME="SelectableList">
<!--4DLOOP ArrayOfItems-->
<OPTION VALUE="<!--4DVAR ArrayOfItems{ArrayOfItems}-->"><!--4DVAR ArrayOfItems{ArrayOfItems}--></OPTION>
<!--4DENDLOOP-->
</SELECT>

The only thing that you need to do is assign an appropriate value into the array before the HTML page is sent out to the browser.

For example:

The following method is called with a 4DACTION. If there is no optional parameter (anything following the name of the method in the 4DACTION URL) then the array is filled with "4D v6.7.1" and "4D v6.7.2". If the optional parameter is present, then the array is instead filled with "WebSTAR v4.1", "WebSTAR v4.2", etc.

` Project Method: SendHTML
C_TEXT($1)
If ($1="")
ARRAY TEXT(ArrayOfItems;2)
For ($i;1;2)
ArrayOfItems{$i}:="4D v6.7."+String($i)
End for
Else
ARRAY TEXT(ArrayOfItems;4)
For ($i;1;4)
ArrayOfItems{$i}:="WebSTAR v4."+String($i)
End for
End if
SEND HTML FILE("Page.html")