Jump to content

Recommended Posts

I have a form that has multiple select objects that are all names "cats[]". When I submit the form, an array is sent with each value that was selected from all of the select objects. Similarly, (on the same page or a different one) I created a set of selects dynamically using createElement() and manually set the name property to "cats[]". When I submit the form with these elements, an array is sent, but only the value of the last select object is in the array.

 

Does anyone have any idea why this would happen?

Link to comment
https://forums.phpfreaks.com/topic/123281-form-element-arrays/
Share on other sites

The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a NAME attribute, include the attribute and value when using the createElement method.

 

I started outputting the innerHTML after creating the objects and realized the name property was only being set as a custom attribute of the object and not as the actual property. I never would have figured out why if it weren't for the good old MSDN!

 

 

Link to comment
https://forums.phpfreaks.com/topic/123281-form-element-arrays/#findComment-636714
Share on other sites

Just when I thought everything was going to work out...

Aparently you cannot specify anything but the tag name when using createElement() in Firefox, so the solution that fixes the problem in IE completely breaks Firefox.

 

Any ideas on a workaround for this without checking for the browser type?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/123281-form-element-arrays/#findComment-636770
Share on other sites

Yes, it works to set a name value and PHP sees it correctly as a name; however, when it is set manually, it won't parse as an array. As soon as I changed the creating code to this:

document.createElement('<SELECT name=\'cats[]\'></SELECT>');

Everything worked perfectly in IE.

Link to comment
https://forums.phpfreaks.com/topic/123281-form-element-arrays/#findComment-636949
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.