My project has a large number of dropdown menus. My current scheme is to create jquery listeners for each control, however, it seems reasonable that a single function could accomplish the same task. Please see the onlick event in the markup.
<div class="input-group">
<div class="input-group-prepend">
<button id="PrimaryPhoneType" class="btn btn-outline-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Type</button>
<div id="ddlPrimaryPhoneType" class="dropdown-menu" onclick="ManageDDlClicks('ddlPrimaryPhoneType','tbPriPhoneType')">
<a class="dropdown-item" href="#">Cell</a>
<a class="dropdown-item" href="#">Home</a>
<a class="dropdown-item" href="#">Work</a>
</div>
</div>
<input type="text" class="form-control" id="tbPriPhoneType" runat="server">
</div>
Current listener scheme:
$('#<%=ddlPrimaryPhoneType.ClientID %> a').click(function () {
$('#<%=tbPriPhoneType.ClientID %>').val($(this).html());
});
Proposed new function:
function ManageDDlClicks(src, tgt) {
let list = document.getElementById(src).getElementsByTagName('a');
console.log(list);
var selItem = list.???
document.getElementById(tgt).value = selItem
}
Debugging & studying the contents of the "list", I see nothing in the nodes that point to which item was selected.