Forum Moderators: open
If it's a drop-down form element...it's one selection only. If you use the <select multiple...> syntax, which allows the user to select more than one item from the list, it becomes a scrolling list. That's when Ctrl+Click and Shift+Click come into play.
Using Javascript to create hidden, positioned layers containing a drop-down form element simulation with added checkboxes that select item(s) from the fake drop-down is one method you might consider, if Javascript becomes an option.
If it's a drop-down form element...it's one selection only. If you use the <select multiple...> syntax, which allows the user to select more than one item from the list, it becomes a scrolling list. That's when Ctrl+Click and Shift+Click come into play.
Not sure about multiple select dropdowns, but I know for a list box, you would put "multiple" in the select tag..ex: <select name="lstBlah" multiple>
Precisely! Then hold the control button on your keyboard to select as many as you want. If you care to keep the code up to date use:
<select name="somename" multiple="multiple">
And, if I'm not mistaken, you need to add an empty set of brackets to the name of the select:
<select name="somename[]" multiple="multiple">
Without the brackets you will only get the value of the last selected option. The brackets force the value to be an array, which can be accessed by:
foreach($_POST['somename'] as $val) {
print $val;
}
(The default <option> value is the text next to it. Indicate an explicit value if you want it to be something different, i.e. <option value="one">1 )
<select name="list1">
<option>1
<option>2
<option>3
</select>
Produces a single-line, drop-down form element from which only one item may be selected. When the form is posted, the element sends its data as "list1=2", or whatever the choice was.
<select name="list1" multiple>
<option>1
<option>2
<option>3
</select>
Produces a four-line (default for "multiple" types) scrolling (if req.) element from which more than one item may be selected, using the Shift and Ctrl keys as we all know how to. For each item selected from this element, a separate variable=value will be posted. If I select 1 and 3, then my form would post "list1=1&list1=3".
<select name="list1" multiple size=1>
<option>1
<option>2
<option>3
</select>
Produces a single-line form element with tiny scrollbars that behaves exactly as my second example, with regard to posting variables and values.
Using an array indicator to attempt to produce an ordered array for multiple selections in this type of form does not do that. With this type of element, there is no automatic array-generation. You may, however, infer an array from multiple element name entries in the posted data. (i.e. loop through variables and form arrays from multiple entries with the same name).
You MAY use the array indicator with checkbox form elements to create an array on posting. i.e.
<input type="checkbox" name="box[]" value=1>1
<input type="checkbox" name="box[]" value=2>2
<input type="checkbox" name="box[]" value=3>3
Will result in three variables being sent, each named "box[]". The "box[]" variable will be an array, however there will be no ordering visible by default.
I said, "Using an array indicator to attempt to produce an ordered array for multiple selections in this type of form [select] does not do that."
Similarly to checkboxes that use an array indicator, form elements of the SELECT type, in the presence of the MULTIPLE paramter and when NAMEd using an array indicator (i.e. list[]) produces the same result as the CHECKBOX-as-array illustration, above.
Like the CHECKBOX array, variables and values passed using a SELECT array can be accessed AS an array on posting.
Sorry 'bout that. And good idea, Birdman! :)
Thanks!