PHP Programming 101

February 10th, 2009

Select multiple HTML tag

Posted by editor in Codes, Information
Tips to simplify your life

Tips to simplify your life

Want to select multiple items from a list? Then you need to use the select multiple tag in HTML. The action handler then takes care of the form when the items are passed through it. What happens though, is that all of them are passed with the same widget name.

For example:
<select name=”var” multiple=”yes”>
The option you select will register with the action handler as var=option1, var=option2, var=option3. This thereby overwrites the previous $var variable’s contents.

The fix is to utilize the “array from form element” feature of PHP.

Use it like so:
<select name=”var[]” multiple=”yes”>
The first item then becomes $var[0], and then $var[1] for the next, and so on.

Hope this <a href=”http://phpprogrammingtips.net/information/looping-statements-doesnt-loop/”>tip</a> helps.

Comments are closed.

Sorry, the comment form is closed at this time.