I have a form which contains:
<button class="submit">Submit</button>
and jQuery code:
$(".submit").click(function(e){
var evt = e || window.event; // IE compatibility
if(evt.preventDefault){
evt.preventDefault();
}else{
evt.returnValue = false;
evt.cancelBubble=true;
}
//....ajax call
});
So, I was wondering what am I doing wrong that in IE7 when I type search term and press enter it goes to my home page(action in form ="/"). Why it does not prevent IE7 from going to default action.
- is it because I am using button tag
- I also tried old way in form
onsubmitcall some function but it fails - or is it because of ajax call?
Additional note:
- I have body and inside that body I have iframe and in that iframe I have form. So, I wonder is it because of iframe.
You are preventing the default action of the button tag, which does not affect input triggered events, also note that jQuery Event object
preventDefault()method is cross-browser, try this: