I'm struggle with making this work and understand how I can call specific button by pressing Enter in Javascript.
As Example I have
$(document).ready(function () {
$('#myText').keyup(function () {
alert(e.keyCode);
});
$('#myButton').button().click(function () {
alert('Button click 1!');
});
$('#myButton2').button().click(function () {
alert('Button click 2!');
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<form action="#">
<button id="myButton">Button</button>
<button id="myButton2">Button2</button>
<input type="text" id="myText" />
</form>
How to make that when I hit enter in the Mytext value It's click on myButton2 ?
DEMO: http://jsfiddle.net/WZ6TM/610/
UPDATE:
The following answers not working as expected, please see my code structure:
$(document).ready(function () {
$('input#manualuser').keyup(function(e) {
if (e.keyCode === 13) $('#search').click();
});
$('#search').click(function search() {
if ($("input#manualuser").val() === '') {
$('#infostatus').html("<label id='infostatus' class='info'>Please Enter Username</label>");
}
else {
$.ajax({
url: "https://" + $seldom + ":443/api/example/" + $("input#manualuser").val(),
type: "GET",
dataType: 'Jsonp',
success: function (result) {....