How to get all elements of a dropdown list into a variable of type array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ahmad Nawaz
    New Member
    • Dec 2010
    • 4

    How to get all elements of a dropdown list into a variable of type array?

    I have a dropdown list which have some elements.
    I want to get all the elements of the dropdown list into a variable of type array.

    Any Idea???
  • Sudaraka
    New Member
    • Jan 2011
    • 55

    #2
    By default when a HTML form with a SELECT (dropdown) element is submitted, it only post the selected value to the server side.

    You can use the onsubmit event of the form in JavaScript to dynamically add hidden INPUT elements to the form with all the values from the dropdown.
    To make it an array on the server side post-fix the hidden element name with [] (i.e. name="dropdownV alues[]"), Then from the server side you can access this array s $_POST['dropdownValues '] (or $_GET['dropdownValues '] depending on how you submit the form).

    Comment

    Working...