4

If enter key is pressed and then search button clicked event is called. My chrome doesn't work . IE is OK . How do I fix ? Thanks in advance

$('#txtSearch').keypress(function(e){
  if(e.keyCode==13)
  $('#btnSearch').click();
});

});

3
  • Check the Program Console for any javascript errors
    – TARUN
    Commented Apr 13, 2017 at 13:54
  • It shows me "search is not defined" JS is Ok to work IE not chrome.
    – Mathew
    Commented Apr 13, 2017 at 15:07
  • And also I found this error in chrome: This page isn’t working Chrome detected unusual code on this page and blocked it to protect your personal information (for example, passwords, phone numbers, and credit cards). Try visiting the site's homepage. ERR_BLOCKED_BY_XSS_AUDITOR
    – Mathew
    Commented Apr 13, 2017 at 15:40

1 Answer 1

2

For chrome the variable name is different, so following should help:

$('#txtSearch').keypress(function(e){
  var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
  if(key == 13)
     $('#btnSearch').click();
  });
});

e.charCode is used in Chrome

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.