Thierry Posted July 6, 2007 Share Posted July 6, 2007 I have a form in which several fields share the same name via an array (<input name="cookie[]" id="cookie[]">). I've been trying to use 'document.getElementById("cookie")[0]' and also 'document.getElementById("cookie[0]")', but neither yield any results. Anyway of getting the field object while its a form array? (The error I get: "Object expected"); Quote Link to comment Share on other sites More sharing options...
arianhojat Posted July 6, 2007 Share Posted July 6, 2007 name="cookie[]" the name is cookie[] not the id, getElementById is only for searching elements with id's. and you may be tempted now to try set id's for all your input elements called 'cookie[]', but ids have to be unique (cant have many elements with all their ids called 'cookie[]'); hence why u must use the name attribute like you are doing so php knows its an array when you submit... You need to access the values via getting the elements in the form. document.forms[0]['cookie[]'] or document.forms['nameOfForm']['cookie[]'] or document.forms[0].elements['cookie[]'] or document.forms['nameOfForm'].elements['cookie[]'] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.