Reputation: 1205
I'm trying to get the button to work without clicking on it.
I tried but with using 'Submit' and 'button', neither works unless user clicks the button.
<input id="txtDusNumber" class="form-control form-control-sm" type="text" />
<input type="submit" name="submit" class="btn " value="Search" id="enter-btn" onclick="ShowCard()" />
<input type="button" class="btn " value="Search" onclick="ShowCard()" />
<script>
function ShowCard() {
var dusNumberVal = $('#txtDusNumber').val();
if (dusNumberVal) {
$.ajax({
url: "@Url.Action("display","Card")",
data: { number: dusNumberVal },
type: 'GET',
success: function (result) {
$('#results').html(result);
},
error: function () {
alert("error...");
}
});
} else {
alert('Please enter Number.');
}
}
</script>
Upvotes: 2
Views: 424
Reputation: 857
Try this:
$(document).keypress(function(e) {
if(e.which == 13) {
ShowCard();
}
});
function ShowCard(){
...
}
What it does is when the page is loaded, once you press enter, the ShowCard function gets executed.
Upvotes: 2