![]() |
|
|
#1
|
|||
|
|||
|
javascript, php accessing form elements
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? |
|
#2
|
||||
|
||||
|
can you post the relevant code.
thanks.
|
|
#3
|
|||
|
|||
|
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
|
|
#4
|
|||
|
|||
|
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.
__________________
What do you mean I can't add a tuple to a string? That's not a tuple! Stupid computer... Silly, but fun |
|
#5
|
|||
|
|||
|
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/...aid/578/fid/61 for an example. |
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| mod_gzip for PHP only | digitalpoint | Site & Server Administration | 6 | Jun 14th 2009 8:58 am |
| Google search quits on OS X.2 w/WebSTAR5.3 | mduke | All Other Tools | 7 | Nov 11th 2008 5:00 pm |
| PHP Safe-Mode permissions, redux | Owlcroft | PHP | 17 | Nov 9th 2008 12:54 am |
| JavaScript vs. PHP links | digitalpoint | PHP | 9 | Jan 23rd 2008 1:47 am |
| Help Needed on Converting specific javascript commands to php such as math.random() | ProductivePC | PHP | 4 | Jun 6th 2004 3:34 am |