javascript, php accessing form elements

Discussion in 'JavaScript' started by dave ner0tic, Apr 11, 2004.

  1. #1
    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?
     
    dave ner0tic, Apr 11, 2004 IP
  2. relaxzoolander

    relaxzoolander Peon

    Messages:
    141
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #2
    can you post the relevant code.
    thanks.
    :)
     
    relaxzoolander, Apr 11, 2004 IP
  3. er2er

    er2er Peon

    Messages:
    9
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #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 :)
     
    er2er, Apr 12, 2004 IP
  4. jimrthy

    jimrthy Guest

    Messages:
    283
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #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.
     
    jimrthy, Dec 9, 2005 IP
  5. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #5
    dave487, Dec 12, 2005 IP