How do I get the selected options from a multiple select box

870 views
Skip to first unread message

d3vid

unread,
Aug 27, 2014, 2:08:38 AM8/27/14
to d3...@googlegroups.com
On my page I have a multiple selectbox such as:

<select multiple="multiple" id="foo">
    <option value="1">Cat</option>
    <option value="2">Dog</option>
    <option value="3">Fox</option>
    <option value="4">Hen</option>
    <option value="5">Albatross</option>
</select>
With jquery I would get all the selected options in an array using 
var selectedValues = $('#foo').val();
How do I do that using D3?


Sebastian Gutierrez

unread,
Aug 27, 2014, 9:35:07 AM8/27/14
to d3...@googlegroups.com
You can do the following:

function multipleChange() { console.log(this.selectedOptions); }

d3.select("#foo").on("change", multipleChange);

This will give you an array that contains 1 or more selection options.  You can then either assign that to something or use it within your multipleChange function....
Reply all
Reply to author
Forward
0 new messages