How to get the input data of multiple select in the form

PHP中文网
Release: 2016-07-28 08:28:18
Original
1662 people have browsed it

How to get the input data of multiple select in the form

The multiple select element supports selecting multiple options. How to get the multiple selected values?

<pre name="code" class="html"><select multiple="multiple" name="states">
  <option value="1">Alabama</option>
  <option value="2">Alaska</option>
  <option value="3">California</option>
  <option value="4">Texas</option>
</select>
Copy after login

If the name attribute of select is written in the above form, the value submitted by the form will be the last option selected.

{
    "states" : "3"
}
Copy after login

should be written as

<select multiple="multiple" name="states[]">
  <option value="1">Alabama</option>
  <option value="2">Alaska</option>
  <option value="3">California</option>
  <option value="4">Texas</option>
</select>
Copy after login

Form data

{
    "states" : [
        "2",
        "3"
    ]
}
Copy after login

The above is how to get the input data of multiple select in the form. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template