MSK MSK - 5 months ago 18
Ajax Question

javascript keycode example

i have done F2 button coding in that i open one modal and on enter key it get submit but my mouse click is not working. I want both it submit with mouse click and also from enter key please help me



<!-- My KeyDown function -->

function keydownList(e) {

switch (e.keyCode) {
case 13:

populateCustomerId();
keyboard: true
break;

case 113:
$("#myModal").modal('show');
keyboard: true
break;
}
}

<!-- My HTML code for Modal -->

<div class="bs-example">
<div id="myModal" class="modal fade" tabindex='-1'>
<div class="modal-dialog" style="width:460px;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Heading</h4>
</div>
<div class="modal-body">
<form class="navbar-form " role="search" style="margin: 0px; padding: 0px;">
<select id="mySelect" size="20" style=width:400px; onkeydown="keydownList(event);">
<c:forEach items="${agentList}" var="agentList">
<option type="button" id="${agentList.get(0)}">
<c:out value="${agentList.get(0)}" />
</option>
</c:forEach>
</select>
</form>
</div>
</div>
</div>
</div>
</div>




Answer

I do not understand what you want But i used jquery for this case

$( "#mySelect" ).keydown(function( event ) {
  if ( event.which == 13 ) {
     console.log("13");
  }
  if ( event.which == 113 ) {
     console.log("113");
  }
});
 
$( "#mySelect" ).click(function() {
  console.log("click");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  <h4 class="modal-title">Heading</h4>
</div>
<div class="modal-body">
  <form class="navbar-form " role="search" style="margin: 0px; padding: 0px;">
    <select id="mySelect" size="20" style=width:400px; onkeydown="keydownList(event);">
      <option type="button" id="1">1</option>
      <option type="button" id="1">2</option>
      <option type="button" id="3">3</option>
      <option type="button" id="4">4</option>
    </select>
  </form>
</div>