views:

133

answers:

1

i have 3 remote validation in my form and 3 of them works with no errors in firefox console. the 3rd one is not working properly in IE. IE gives me the error "object doesnt support this property"

this gives an error in IE check.php:

< ?php

$sql="select * from people where email = '".$email."'";
$row=mysql_query($sql,$db_connection);
if (!$row)
{
    die('Error: ' . mysql_error());
}    

if (mysql_num_rows($row) > 0)
{
    $output = false;
} 
else 
{
    $output = true;
}
echo json_encode($output);

?>

here is the corresponding jquery:

email: {// compound rule
                        required: true,
                        email: true ,
                        remote: "check.php"
                },  

any ideas why its throwing an object error in IE. note firefox error console doesn't show any errors! thanks

+1  A: 

We'd have to see the page to be sure, but a common reason for IE's “Object doesn't support this property or method” error is that you've got a element on the page whose name or id attribute contains the same name as an implicit global variable.

IE6-7 has an unfortunate non-standard behaviour of copying references to named/IDd elements into properties of the window object:

<div id="foo">bar</div>

alert(window.foo); // the div node

This means they share a namespace with variables:

<div id="foo">bar</div>

var foo= 3;
alert(window.foo); // now 3

But, in another unfortunate non-standard behaviour, if you don't tell it that you want a variable, IE gets confused. It tries to assign any new values to the element node itself, which will fail:

<div id="foo">bar</div>

foo= 3; // implicit global variable in other browsers. Error in IE

This also occurs when you forget var and make an accidental global in a function:

function bof() {
    foo= 3; // Error in IE
}

So, you'll need to go through your script looking for variables you've assigned to without remembering to include a var statement for them. It's not just good practice (and required by ECMA262-5's ‘strict mode’ JS in the future) — it stops IE from being stupid and breaking your pages.

Incidentally this:

$sql="select * from people where email = '".$email."'";

Is a dangerous SQL injection security hole. When constructing SQL queries you must use mysql_real_escape_string() over any text you wish to insert into a string literal.

bobince