开发者

Pressing enter in auto suggest box is submitting main form

I've used autoSuggest in PHP now pressing enter in auto suggest box is submitting main form. How do i disable form submission while开发者_如何学C I use auto suggest.


I'm not entirely sure what you are looking for, but you might consider using jQuery and preventDefault(). Check it out: http://api.jquery.com/event.preventDefault/


im guessing you want something like this

$(document).ready( function() {
$("#changeSite").keypress(function (event){ return event.keyCode == 13 ? false : true; });
});

change #changeSite to match your form


When you call your keypress function and bind it to an event, make sure the event doesn't call the form using event.preventDefault();:

$("#input_id").keypress(function (event){ 
   event.preventDefault();
   if(event.keyCode==13){
     // call auto complete function
   } else {
     return false;
   }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜