I have a form with select form elements named mb[] so that they will be an array for the results page (php) to access. I have a checkbox that when checked enables the select fields to be enabled. my problem is accessing the select elements because they're named mb[] how can i do this?
You can either use "document.getElementsByName('mb[]')" which returns a collection (an array) of elements that can be acessed through [_number_] convention, or assign unique ID's to those elements (each element could have a NAME shared among others and a unique ID). eg #1 document.getElementsByName('mb[]')[0] return first elemrnt with name "mb[]" eg #2 document.getElementById("mb_01"), assuming that first element has ID="mb_01" Hope that helps
This is good advice, assuming you're not worried about supporting older browsers. Personally, I don't support them (unless I'm being paid ridiculously well to do so). But you also asked about PHP. Crap. This is what happens when I work too many hours and try to juggle too many programming languages at once. A good programmer should be fluent in many different languages. When you work in 4 of them in the same week, they sort of blur together. If I recall correctly, PHP does basically the same thing as JavaScript. $_POST["mb[]"] holds an array of the values that were chosen. But it seems as though you might have to do something in php.ini to enable this, as opposed to just getting the value of the last control with this name? Never mind. Ignore me. I obviously need to just give up and get some sleep.
To process the form with php you need to loop through the array which is populated by your select box. see http://www.faqts.com/knowledge_base/view.phtml/aid/578/fid/61 for an example.