I was getting this strange error when I was trying to write a function as simple as asking for confirmation while deleting a particular record. On click of the ‘Delete’ link, it used to give me this error “Object Expected” in IE 6.

The code that I had written before the error was like:

<script language=”javascript” type=” text/javascript”>
function deleteConfirmation(id)
{
var answer = confirm(”Are you sure you wish to delete this entry?”);

if (answer){
location.href = ’some url’;
}
else{
return false;
}
}
</script>

In the first glance, I am not sure how many of you will be able to point out what the error is. The code after correcting this error looks like:

<script language=”javascript” type=”text/javascript”>
function deleteConfirmation(id)
{
var answer = confirm(”Are you sure you wish to delete this entry?”);

if (answer){
location.href = ’some url’;
}
else{
return false;
}
}
</script>

Well, the difference between the two pieces of code lies in the first line:

<script language=”javascript” type=”text/javascript”>

The error was occurring as there was a space preceding in the value given in the ‘type’ attribute. I removed the extra space before “text/javascript” and that’s all what it took to resolve this error. Oh yes, this error was occurring only in IE 6 & not in Firefox.

Related posts:

  1. Change button ‘type’ for dynamic buttons in IE using Javascript
  2. “Unknown runtime error” in IE8 while using ajax
  3. SHTML Wrapper - 500 Server Error
  4. Facebook apps - Are they spamming?