NYCPHP Meetup

NYPHP.org

[nycphp-talk] form element arrays

Jeff Knight jeff.knight at gmail.com
Mon Oct 31 19:24:06 EST 2005


I've been known to get quite carried away with naming form elements as
nested arrays, often dynamically generated, and have found that using the
elements[] property of the form object works best for me. To access the
elements of the form named 'example_form'

<form action='x.php' name='example_form' method='post'>
<input type='hidden' name='userdata[hidden_group_1][first]' value='one'>
<input type='hidden' name='userdata[hidden_group_1][second]' value='two'>
<input type='hidden' name='userdata[hidden_group_2][third]' value='three'>
<input type='hidden' name='userdata[hidden_group_2][fourth]' value='four'>
</form>

use a javascript like

document.example_form.elements['userdata[hidden_group_2][third]'].value



On 10/31/05, Marc Antony Vose <suzerain at suzerain.com> 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,
>
> --
> Marc Antony Vose
> http://www.suzerain.com/
>
> Never underestimate the power of human stupidity.
> -- Lazarus Long
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20051031/62ac02f8/attachment.html>


More information about the talk mailing list