I've got a Bootstrap dropdown list which is bound to some data with Knockout and that works as expected. However, when I select an item in the dropdown, I want to be able to display that as the dropdown text.
javascript:
<script type="text/javascript">
$(".dropdown-menu li a").click(function () {
$(this).parents(".btn-group").find('.selection').text($(this).text());
$(this).parents(".btn-group").find('.selection').val($(this).text());
});
</script>
html:
<asp:Content ID="body" ContentPlaceHolderID="body" runat="Server">
<div id="main">
<div class="container">
<div data-bind="template: { name: 'TillGroups' }"></div>
</div>
</div>
<script id="TillGroups" type="text/html">
<label for="ddm">Till group:</label>
<div id="ddm" class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" data-bind="foreach: StockCount.ReadTillGroupsValue">
<li><a role="menuitem" tabindex="-1" href="#" data-bind="text: Name"></a></li>
</ul>
</div>
</script>
</asp:Content>
P.S. I've search on here for similar questions such as the following but the answers posted there don't appear to work:
How to Display Selected Item in Bootstrap Button Dropdown Title