-1

I have the following code inside my asp.net 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 ?

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
John John
  • 1
  • 72
  • 238
  • 501

2 Answers2

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;
1

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;
}
mrwjr2003
  • 13
  • 3