Bhavsar1311
Bhavsar1311

Reputation: 773

jquery javascript navigation (redirection) issue

the project is in MVC and i used this code in _Layout page and the control txtSearch is in layout page too

what below code doing is when i write something on text (txtSearch) and press enter that redirect to stockList page with entered parameter

$('#txtSearch').keypress(function(event) {
  debugger;
  var keycode = (event.keyCode ? event.keyCode : event.which);
  if (keycode == '13') {
    var strUrl = '/stocklist/All%20Categories-All%20Makers-All%20Models-0-0-' + $('#txtSearch').val();
    location.href = strUrl;
  }
});

what problem i got is in some page this action working very fine but while comes to stocklist page its not working properly will you please help me out from this.

Upvotes: 0

Views: 57

Answers (1)

jimmy darji
jimmy darji

Reputation: 56

$('#txtSearch').keypress(function (event) {
    debugger;
    var keycode = (event.keyCode ? event.keyCode : event.which);
    if (keycode == '13') {
        var strUrl = '/stocklist/All%20Categories-All%20Makers-All%20Models-0-0-' + $('#txtSearch').val();
        location.href = strUrl;
        return false;
    }
});

just add return false; in end of the code

Upvotes: 1

Related Questions