One of the most tedious chores when using a form select list is filling it with the options, especially with a long list of options. Since most of my long lists are already in a text file, I use this script to load the list box options when the page loads instead of typing them all in while designing the page.
After extracting the selectfiller.php file, upload it to your site. You will also need to upload the text file containing the options to be loaded into the select list. By default, the script will look in its own directory for the text file, but you may upload it to a different directory and use a parameter instructing the script where to look.
Open SiteSpinner and place a form select list on your work page. Make note of the form and the name you gave the select list; these are needed to tell the script which form select list will be filled. Then open a code object and enter the following:
Modify the “src=…” attribute (if needed) to include the path directory of the script file. There are five parameters that may be passed to the script file as a query string. The first two are required, the remainder are optional.
| ?obj=form.select | (Required) This specifies the SiteSpinner form and select list to be filled. It is case sensitive so the value must match what is displayed in SiteSpinner. The value is formed by joining the form name and the select list name with a period. Example: ?obj=myform.state_list where myform is the name of the form and state_list is the name of the select list. |
| &file=text-file | (Required) This specifies the input text file containing the name-value pairs used to fill the selection list. If the text file is not in the same directory as the script, you must include the path info to its location. Examples: &file=veggies.txt &file=./text/myopts.txt |
| &swap=swap | (Optional) This parameter indicates that the name-value pairs in input text file are in reversed order and should be reversed. Example: &swap=swap |
| &caption=caption-text | (Optional) This parameter contains the text to be inserted as the first select option; it has no associated value. If omitted, the word “Select” will be displayed. Example: &caption=Choose a City |
| &default=item-number | (Optional) This parameter specifies which select item (if any) should be shown when the page is displayed. The parameter value specifies the list item number to be displayed, where 0 is the first item number (select lists are zero-based). |
More than one select list can be filled by executing the script for each list. For example, if you have two select lists on your page (obj1 and obj3), both can be filled by executing the following:
<script src=”selectfiller.php?obj=form.select2&file=text2.txt”></script>
The demo illustrates the various optional parameters using three possible input files: a countries text file, a US states text file, and a month name text file. Choosing a file loads the select list with data found in the file. You can also change the list’s caption, reverse the name-value order and set the 7th list item to be displayed as the default selection.
[Note: The demo also uses AJAX to dynamically execute script code via onChange events. Those of you interested in this should view the HTML source for the lower page frame.]
Text File Format
The text file is created as a plain text file (no HTML) with each line containing a single selection list option. Each list option is in the form:
option-name::option-value
where option-name is the list’s displayed option, and option-value is the option passed through the form. Note that the two option parts are separated by a double-color (::). This delimiter can be changed in the selectfiller.php script file by altering the line
to change the ‘::’ to the desired characters.
If your text file is formatted as “option-value::option-name”, you can use the “swap” parameter to tell the script the two options are reversed. The script will also ignore leading and trailing spaces and other whitespace (such as tabs) surrounding your values in case your file is generated from an external source, such as a database query or spreadsheet.
Contact the LowTechGeezer
VM User's Forum
Bruceee's Sandpit
Webmaster's Corner
Other Useful Sites
trying to understand php
I must be a moron. I don’t understand a thing I’ve read. I built the form I want to use, but I have no idea on how to make it function. Could you please help? This is the link to my page, feel free to provide me whatever help you have. http://www.rgvtda.com/submit.html
Thanks,
Moe
Jack,
I had some files in the wrong location after my last migration. Thanks for letting me know. The demo should be working now.
I cannot get the form “demo” to work. I cannot understand these forms either. I can put them on my page and they look great, but cannot find instruction on code to value fields, etc. I’ve never felt so doggone dumb.
I do like your pages. Your information is very helpful in most areas.
Thank you,
Jack