[nycphp-talk] form element arrays
Dan Cech
dcech at phpwerx.net
Mon Oct 31 17:27:53 EST 2005
There are a couple of ways I know of to work around this problem.
1. Set your form up like:
<select name="myselect[]" id="myselect" multiple="multiple">
<option ...
</select>
The you can access it in javascript via:
document.getElementById('myselect')
2. Use javascript on the onsubmit action of the form to dynamically
rewrite the names of multiple select boxes.
Personally I tend to use 1, and it seems to work ok.
Dan
Marc Antony Vose wrote:
> Hi there:
>
> Honestly, I'm posting this before I've completely exhausted my
> troubleshooting options, but I figured someone might be bored enough
> to beat me to it.
>
> I have a select element for which I need to return multiply selected
> items to PHP. In other words, I guess it has to have the name
> 'something[]', with brackets.
>
> However, I also need to add options to the select list via
> javascript, but it seems like the addition of the brackets makes the
> form element name invalid, by javascript's standards, since you
> access attributes of objects with brackets (i.e., JavaScript can't
> see an element named 'something[]').
>
> It looks like I'm going to have to use the select list to just
> display the options to the user, but really use DOM to dynamically
> add hidden form elements to the form which hold the values I need, as
> a nasty workaround, but I was wondering if anyone else had any silver
> bullet for this.
>
> Cheers,
More information about the talk
mailing list