- jQuery Examples
- Examples - Home
- Examples - Set up
- Examples - Selectors
- Examples - Attributes
- Examples - Traversing
- Examples - CSS
- Examples - DOM
- Examples - Events
- jQuery Useful Resources
- jQuery - Quick Guide
- jQuery - Useful Resources
jQuery Examples - $("select").val(['Orange', 'Mango'])
Description
This selects Orange and Mango options in a dropdown box with options Orange, Mango and Banana.
Syntax
Here is the simple syntax to use this method −
selector.val([value1,value2]);
Parameters
value1,value2]Array of values to be selected in the matched element.
Example
Following example selects Orange and Mango options in a dropdown box with options Orange, Mango and Banana.
Live Demo<html> <head> <title>The jQuery Example</title> <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script type = "text/javascript" language = "javascript"> $(document).ready(function() { $("select").val(['Orange', 'Mango']); }); </script> </head> <body> <div> <form name = "sampleForm"> <select multiple> <option value = "Mango">Mango</option> <option value = "Orange">Orange</option> <option value = "Banana">Banana</option> </select> </form> </div> </body> </html>
This will produce following result −
jqueryexamples_attributes.htm
Advertisements
To Continue Learning Please Login
Login with Google