2

On a page I have a google search-field and a separate form for a login. In order to make the search-field work with enter, I included the following script:

$('#searchBox').keydown(function (event) {
    if (event.keyCode == 13) {
        document.location.href = "someTargetPage.html";
    }
});

The only problem is that in that case the form would be sent because the search-field is included within the form, which I can't change due to the architecture of dot net nuke. I tried to prevent that like this:

$('form').delegate('input:submit', 'click',
    function () {
        return false;
});

Now the search-field does work nicely with enter, but the submit-button from the form won't work! Is there a way to check from where the trigger comes and either allow or deny it?

Thx for any tipps!

Ben Lee
  • 52,489
  • 13
  • 125
  • 145
sl3dg3
  • 5,026
  • 12
  • 50
  • 74

2 Answers2

1

Remove your code that stops the input button from working (your delegate on input:submit). You just need to make #searchBox not propagate the event up to the form. It's the search box handler that needs to cancel the event by returning false:

$('#searchBox').keydown(function (event) {
    if (event.keyCode == 13) {
        document.location.href = "someTargetPage.html";
        return false;
    }
});
Ben Lee
  • 52,489
  • 13
  • 125
  • 145
0

if you actually want to totally disable the form, just return false on it's onsubmit event:

$("#searchform").live("onsubmit", function(){ return false; });
Leon
  • 4,532
  • 1
  • 19
  • 24