jQuery - Get Select Value and Update Div With Multiple Select Menus -
jsfiddle: https://jsfiddle.net/x9bbb14n/
as example, have following html:
<select name="sweets"> <option>chocolate</option> <option selected="selected">candy</option> <option>taffy</option> <option>caramel</option> <option>fudge</option> <option>cookie</option> </select> <div class="sweets"></div> <select name="cars"> <option>ford</option> <option selected="selected">jaguar</option> </select> <div class="cars"></div> i have jquery
$( "select" ).change(function () { var str = ""; str = $( "select option:selected" ).text(); $( "div" ).text( str ); }) .change(); i know it's incorrect want able select 1 option , its div updated, go menu, select option , update its div
any obvious things i'm missing?
thanks
use $(this) getting current object in jquery
$("select").change(function () { var str = $("option:selected", this).text(); $('.' + $(this).attr('name')).text(str); }).change();
Comments
Post a Comment