Following is my JavaScript (mootools) code:
$('orderNowForm').addEvent('submit', function (event) {
event.preventDefault();
allFilled = false;
$$(".required").each(function (inp) {
if (inp.getValue() != '') {
allFilled = true;
}
});
if (!allFilled) {
$$(".errormsg").setStyle('display', '');
return;
} else {
$$('.defaultText').each(function (input) {
if (input.getValue() == input.getAttribute('title')) {
input.setAttribute('value', '');
}
});
}
this.send({
onSuccess: function () {
$('page_1_table').setStyle('display', 'none');
$('page_2_table').setStyle('display', 'none');
$('page_3_table').setStyle('display', '');
}
});
});
In all browsers except IE, this works fine. But in IE, this causes an error. I have IE8 so while using its JavaScript debugger, I found out that the event
object does not have a preventDefault
method which is causing the error and so the form is getting submitted. The method is supported in case of Firefox (which I found out using Firebug).
Any Help?
I was helped by a method with a function check. This method works in IE8
in IE, you can use
to achieve the same result.
And in order not to get an error, you can test for the existence of preventDefault:
You can combine the two with:
return false
in your listener should work in all browsers.To disable a keyboard key after IE9, use :
e.preventDefault();
To disable a regular keyboard key under IE7/8, use :
e.returnValue = false;
orreturn false;
If you try to disable a keyboard shortcut (with Ctrl, like
Ctrl+F
) you need to add those lines :Here is a full example for IE7/8 only :
Reference : How to disable keyboard shortcuts in IE7 / IE8
Tested on IE 9 and Chrome.