jquery - How to set a javascript function to onchange action in boostrap dropdown? -
this boostrap drop down query.
<div id="drop"> <ul class="dropdown-menu" role="menu" aria-labelledby="menu1"id="mymenu"> <% try { resultset r = db.jdbc.getconnection().createstatement().executequery("select name item "); while (r.next()) { %> <li role="presentation" id="menu2" ><a role="menuitem" tabindex="-1" href="#"><%=r.getstring("name")%></a></li> <% } } catch (exception e) { e.printstacktrace(); } { if (db.jdbc.getconnection() != null) { db.jdbc.getconnection().close(); } } %> </ul> </div>
search item name in db. want when it's value clicked. tried code. no output.
<script > $(document).ready(function() { $('#drop').change(function(event) { var $name = $('.dropdown-toggle').dropdown(); alert($name); }); }); </script>
i searched boostrap description also. couldn't find answer please me.
its not clear trying achieve when value dropdown clicked, assuming looking event triggered each time clicks item dropdown try similar this:
$(document).ready(function () { $('#mymenu li').click( function (clickeditem) { alert(clickeditem.currenttarget.innertext); //do other stuff }); });
you can see demo of solution here