Created
July 14, 2014 07:16
-
-
Save sebby/08a412bdc717c556552e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta name="description" content="[add your bin description]" /> | |
| <meta charset="utf-8"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <select id="select1" multiple> | |
| <option value="1">valeur 1</option> | |
| <option value="2">valeur 2</option> | |
| <option value="3" selected>valeur 3</option> | |
| <option value="4" selected>valeur 4</option> | |
| <option value="5">valeur 5</option> | |
| </select> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Return an array of the selected opion values | |
| // select is an HTML select element | |
| function getSelectValues(select) { | |
| var result = []; | |
| var options = select && select.options; | |
| var opt; | |
| for (var i=0, iLen=options.length; i<iLen; i++) { | |
| opt = options[i]; | |
| if (opt.selected) { | |
| result.push(opt.value || opt.text); | |
| } | |
| } | |
| return result; | |
| } | |
| console.log(getSelectValues(document.getElementById('select1'))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment