I'm using a piece of Js code to show the selected item of a Bootstrap drop down. I have several drop downs on my ASP.NET page. When I use this code and select an item of the first (or any) dropdown, all the other drop downs change their value as well. I'm a newbie to Javascript and Bootstrap and have searched for an issue like this, but have not found any results...
JS Code (found here):
$(function(){
$(".dropdown-menu li a").click(function(){
$(".btn:first-child").text($(this).text());
$(".btn:first-child").val($(this).text());
});
});
I have tried a few interesting variations of the above. Including one that replaces ".btn:first-child" with the name of a div class for each individual drop down, and then listing all of them in the hopes that JS will know which dropdowns to change... that didn't work.
Markup Used (I am using several dropdowns in row/col-md-6):
<div class="row">
<div class="col-md-6">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="ddlForwardTo" data-toggle="dropdown">
Select a Forward To
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
</ul>
</div>
</div>
<div class="col-md-6">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="ddlManufacturing" data-toggle="dropdown">
Select a Manufacturing contact
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
</ul>
</div>
</div>
</div>
Any help appeciated.
UPDATE:
To sum up the frustration of more than 12 hours of work - be sure to clear your cache in Google Chrome if you get this type of error! Chrome caches Javascript.
Chrome -> Tools -> Clear browsing data... -> Select "Cached images and files" and clear it.