CURRENT PROJECTS
loading
CATEGORIES AND POSTS
loading
overset
DEVELOPMENT LOG FOR JIM PALMER
Posted 03/05/2008 in ajax


When you build an AJAX application that is served to IE6 and IE7 clients - you'll probably run into the obscure "Invalid Argument" error:
[name] => Error
[number] => -2147024809
[description] => Invalid argument.
[message] => Invalid argument. 

If you see this returned by the Error object that gets passed with a try {} catch {} throw or a window.onError throw - it ends up not being very helpful. I've scoured information for some time on some areas that you might want to look at in your Javascript code that might be the cause of the issue:

mal-formed Javascript style changes
A lot of the time you'll be dynamically setting styles in Javascript, i.e. the width of a div as follows:
document.getElementById('obscureDiv').style.width = parseInt(newWidthValue) + 'px';

You must be sure that newWidthValue is in fact an instanceof Number or that it does not equal null or that it does not equal NaN either. parseInt() itself will return a NaN in certain conditions. For instance if:
newWidthValue = 'NOTNUMERIC';
alert(parseInt(newWidthValue )); // will alert with NaN
document.getElementById('obscureDiv').style.width = parseInt(newWidthValue) + 'px'; // will throw "Invalid Argument" error because it will be trying to set the width to 'NaNpx'

adding child nodes to document
Always appendChild(), replaceChild() or insertBefore() before setting any of the new element's attributes:
var newDiv = document.createElement('div');
document.getElementById('obscureDiv').appendChild(newDiv);
newDiv.id = 'newDiv';
newDiv.innerHTML = '<b>success</b>';

Always use a createElement() function on the same document you're going to be calling appendChild() or replaceChild(). A lot of time you'll see (with frames and iframes):
var newDiv = document.getElementById('obscureDocument').document.createElement('div');
document.getElementById('obscureDocument').document.appendChild(newDiv);

eval()
Watch for these errors being caused by mal-formed dynamic eval()s.

odd causes with Internet Explorer
Found an odd one today with IE7 throwing the Invalid Argument error with the following:
onMouseOver="this.style.clip='auto';"
// or
onMouseOver="this.style.clip='';"

This was all with doctype: "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
comments
loading
new comment
NAME
EMAIL ME ON UPDATES
EMAIL (hidden)
URL
MESSAGE TAGS ALLOWED: <code> <a> <pre class="code [tab4|tabX|inline|bash]"> <br>
PREVIEW COMMENT
TURING TEST
gravatar