Question about forms.

Good day.

I have a question about forms. So that is my situation. In form there are some DropLists (<select></select>) like

country: [ ------ ]

and I need to implement something like [+] button that add same DropList with same items (<option></option>) and name of select. So goal is make an array of Drop boxes. In html I want by pressing [+] change that:

<select name=counties[]><option>usa</option><option>canada</option></select>

to this and without reloading page:

<select name=counties[]><option>usa</option><option>canada</option></select>

<select name=counties[]><option>usa</option><option>canada</option></select>

As far I see something like JQuery.append is required. But may be framework has some mechanism of web form transformation with adding new elements for that form via javascript without page reloading.

I hope you understand main idea.

Hi stanley,

I don't think Yii has any feature to perform such tasks as client-side select box duplication… I guess you'll have to write your own jquery code.

(remember that if you set the name attribute of your select boxes to the same value, you’ll have a problem retrieving POST values ;) … your example would not work)

8)

Thank you for you answer. But look, I think my example is correct. Because I use a name countries[] instead of countries. When I finish variable name with [] I have an array on POST output instead of single variable. So if you have a

<input type="text" name="look[]">

<input type="text" name="look[]">

<input type="text" name="look[]">

It's post all three fields values in a look array. Am I right?

yes you’re right…and I was wrong  :(

(I don't know what I was thinking) …

8)