Saturday, 9 December 2017

javascript - My JS selector for is not working

I'm using multiple Bootstrap dropdown controls and need to
set a value to an input field when a list item of a specific dropdown is selected. For
example, say I have 3
dropdowns:




  • ulSaukContact

  • ulMoselContact

  • ulShipContact




All
three are running on the server, and I need to get the value of each so I can save them
somewhere. So I figured I should probably save the value of each to a hidden input field
that I can reference later. Here is my attempted JS code for doing
this:



$("#ulSaukContact li
a").on("click", function () {
alert('sauk'); // <--- Alert is not
shown
var elem = document.getElementById("inpSaukValue");

elem.Value =
$(this).text();
});



and
the accompanying markup



             class="dropdown">

id="ulSaukContact" class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1"
runat="server" style="width: 100%">



type="hidden" />




When I
run the app and select a value in the Saukville dropdown, no alert is
displayed.
Note that the li's and a's within the ul is created on
Form_Load so they can be populated with data. I think my selector is wrong. I cleared
out my cached files in Chrome (which caused issues before) and I still do not see the
alert.



Any advice appreciated (thanks for all
the recent JS/BS/JQ advice)...

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...