Search code examples
javascriptjqueryselectcheckboxradio-button

Use jQuery with <select> option


I found a jQuery code which allows me to check id a certain radio/checkbox is checked, and then show something else based on the selection. Is there a way to do this with a <select> option? For instance, if I have a select box that has "Bread", "Milk", and "water" as the options, and the user clicks "bread", it would show "BREAD is $2.99", but if you select "Milk", it'll say "MILK is 2.49". The code is at http://jsfiddle.net/U9Jsh/.

Thank You.


Solution

  • Sure. You can use the .change() handler on the select and $(this).val() in the handler. See this fiddle for an example that shows changing based on bread and milk. It's a small self-contained example not based off of your fiddle that should get you started. You can also use the "option:selected" selector.