Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within HTML Pages with CSS and JavaScript
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
HTML Pages with CSS and JavaScript
jquery newbie question on select element
Nimchi Yung
Ranch Hand
Posts: 71
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
If I have a select element like this:
.. <select id="myselect" size="5" multiple="multiple"> <option value="-1">--Please select your favorite --</option> <option value="1">Pizza</option> <option value="2">Steak</option> <option value="3">Burger</option> <option value="4">Pasta</option> </select> ..
I like to have a function to return the array of selected values.
What I have is like this:
function getResult() { var selElem = $('myselect')[0]; var arr = []; for (var i = 1; i < selElem.length; i++) { if (selElem.options[i].selected) arr.push(i); } return arr; }
Is there any better way (less code) to achieve this?
--Nimchi
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
$('#myselect).val();
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Nimchi Yung
Ranch Hand
Posts: 71
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Cool!
Thanks,
Nimchi
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Getting a value from a DOJO filteringselect
get all from select multiple
Drop Down Box in Struts - Select Default Value Implementation
Is this a bug of IE regarding select?
Retrieving a drop-down list value.
More...