I'm trying to call ajax() when users enter on input box without page load but it's calling this ajax method when users typing on input box. My input box is following :
<input type="text" name="search" id="txt_name" placeholder="Keyword"/>
Jquery./ Ajax Code;
$(document).ready(function(){
$("#txt_name").keyup(function(){
var value = $('#txt_name').val();
$.ajax({
type:"post",
url:"doSearchEnter.php",
data :{
'key' : value
},
success:function(res){
$('#showSearchResult').html(res);
}
});
});
});
How do I call I this ajax() after user enter on input box without page load ?
Update:
$('#txt_name').on('click', 'submit', function(e) {
e.preventDefault();
$.ajax({
type:"post",
url:"doSearchEnter.php",
data :{
'key' : value
},
success:function(res){
$('#showSearchResult').html(res);
}
});
});
Update 2 :
<form>
<input type="button" name="given_name" value="Given Name" class="search_submit" id="given_name"/>
<input type="button" name="company_name" value="Company Name" class="search_submit" id="company_name"/>
<input type="button" name="cdid" value="ID" class="search_submit" id="cdid"/>
<input type="text" name="search" id="txt_name" placeholder="Keyword"/>
</form>
$('form').on('click', 'submit', function(e){
e.preventDefault();
});
$('form').on('keyup', '#txt_name', function(e){
if(e.keyCode == '13'){
$.ajax({
type:"post",
url:"doSearchEnter.php",
data :{
'key' : value
},
success:function(res){
$('#showSearchResult').html(res);
}
});
}
});
keyupevent relates to: The "up" part of a keystroke (the parts are keydown [which might repeat if the user holds it down and key repeat starts], keyup, and keypress [which might repeat]). If you want it to happen on another event, use another event.