Skip to content

Instantly share code, notes, and snippets.

@henryhu712
Created March 28, 2016 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryhu712/767557b33b318d73b57b to your computer and use it in GitHub Desktop.
Save henryhu712/767557b33b318d73b57b to your computer and use it in GitHub Desktop.
Multiple values select

HTML

HTML structure

<label for="select-age">AGE</label>
<select id="select-age" multiple="multiple" size="5" name="age[]">
    <option value="under20" selected="selected">Under 20</option>
    <option value="20-24" selected="selected">20-24</option>
    <option value="25-34" selected="selected">25-34</option>
</select>';

JavaScript/jQuery

Construct Get request:

var fage = $('#select-age').val();
var ages = '';
for (var ix in fage) {
    ages += '&age[]=' + fage[ix];
}
window.location.href = '/wp-admin/admin.php?page=box-applications' + ages;

PHP

Get the value:

  $values = isset($_GET['age']) ? $_GET['age'] : array();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment