- 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")
Description
This would select Orange option in a dropdown box with options Orange, Mango and Banana.
Syntax
Here is the simple syntax to use this method −
selector.val(value);
Parameters
value This is the value to be selected in the matched element.
Example
Following example would select Orange option in a dropdown box with options Orange, Mango and Banana.
<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"); }); </script> </head> <body> <div> <form name = "sampleForm"> <select> <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