I have the following code inside my asp mvc web application:-
<script>
function validateForm(e) {
if ($("[name=ip]").val() == "" && $("[name=mac]").val() == "") jAlert('Please enter atleast one search value.', 'Message');
e.preventDefault();
}
</script>
but when accessing this Script on IE i will get the following error:-
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'preventDefault'
while when accessing the web page that uses this script using Firefox, chrome it will work fine, can anyone advice please ?
I have the following code inside my asp mvc web application:-
<script>
function validateForm(e) {
if ($("[name=ip]").val() == "" && $("[name=mac]").val() == "") jAlert('Please enter atleast one search value.', 'Message');
e.preventDefault();
}
</script>
but when accessing this Script on IE i will get the following error:-
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'preventDefault'
while when accessing the web page that uses this script using Firefox, chrome it will work fine, can anyone advice please ?
Share edited Oct 30, 2013 at 15:42 Tushar Gupta - curioustushar 57.1k24 gold badges106 silver badges109 bronze badges asked Oct 30, 2013 at 15:37 John JohnJohn John 1 6- 4 how are you calling the function? – ThiefMaster Commented Oct 30, 2013 at 15:38
- see this other stackoverflow question – Josiah Ruddell Commented Oct 30, 2013 at 15:39
-
2
Internet Explorer's event object doesn't have a
preventDefault()
function, you'll need to set itsreturnValue
property tofalse
instead. javascripter/faq/eventpreventdefault.htm – Anthony Grist Commented Oct 30, 2013 at 15:40 - 2 @AnthonyGrist: Or use jQuery to bind the event. – gen_Eric Commented Oct 30, 2013 at 15:41
- 1 @RocketHazmat Or that! I didn't notice the jQuery tag on the question. – Anthony Grist Commented Oct 30, 2013 at 15:42
2 Answers
Reset to default 3//for IE
e.returnValue = false;
//for browsers supporting preventDefault()
if(e.preventDefault) e.preventDefault();
or short record:
(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
IE doesn't always like preventDefault
Check to make sure the broswer like preventDefault, if it doesnt, use returnValue.
if(e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}