jQuery Dialog error in IE7. Runtime error: invalid argument

So if you’re using jQuery UI dialogs, you may run into issues with IE 7. Apparently the value of a usually ‘undefined’ javascript variable can get set to ‘NaNpx’ in IE7. I had to change the jQuery base code to get a dialog ui component to work.

I was getting the following runtime error: “Line: 1102 Error: invalid argument.”

This error comes from code around line 1101 in jquery-1-2-6.js.

So I think my version of jQuery had already been modified or comes from an older or different source. My code follows, but the most recent 1-2-6 jQuery script has code that is like the comment Dom left (thanks – that code looks more like the most recent release of jQuery).


/* MODIFIED 7/31/08 BY NATE
* WAS THIS, but IE7 was throwing an error
if ( value != undefined )
elem[ name ] = value;
*/
if ( value != 'NaNpx' && value != undefined)
elem[ name ] = value; //NATE - Sometimes the value would come up as NaNpx in
IE and causes an error

jquery runtime error for dialog

17 thoughts on “jQuery Dialog error in IE7. Runtime error: invalid argument”

  1. I just came across this issue today. My error occured at line 1120. I also am running 1.2.6 but we have different code which is strange.

    The original for me was:
    [CODE]
    if ( set )
    elem[ name ] = value;
    [/CODE]
    To get it to work I changed it to:
    [CODE]
    if(set && value != ‘NaNpx’)
    {
    elem[ name ] = value;
    }
    [/CODE]

  2. Thanks for publishing this. Fix worked for me as well — and as with Dom, my error pointed to line 1120. This also affects IE6, which the fix addresses also.

  3. Hi,
    I just encountered this problem with the latest build (1.2.7pre), but including the jquery-ui-themeroller.css bundle fixed it.

  4. Its actually caused by IE’s auto margins so setting the margin in css should fix the problem. I fixed mine by adding margin:0 to ui-dialog-content class

  5. Hay all,
    I hit the same issue – I could not solve it with the css fix that Brinley Ang suggested (this was my preferred solution). Instead I had to add the following to catch the error:

    if ( value != ‘NaNpx’ && value != undefined && value != ‘none’)
    elem[ name ] = value; //NATE – Sometimes the value would come up as NaNpx in IE and causes an error

    Thanks for the nudge in the right direction though, I would not have found this without it…

    Regards

    Jamie

  6. Hmmm, I’m back, I got the same problem crop up again, this time value was equal to “0 NaNpx 0 40px” so I modified my fix as follows:

    if ( value != ‘NaNpx’ && value != undefined && value != ‘none’ && value.indexOf(‘NaNpx’) == -1 )
    elem[ name ] = value; //NATE – Sometimes the value would come up as NaNpx in IE and causes an error

    This checks for the existance of NaNpx anywhere in the value string. For now this has done the job, and I guess in any string that NaNpx shows up in this context it should hold water.

    Hope it helps 😉

    J

  7. All these errors (including ‘NaNem’ and “0 NaNpx 0 40px”) are because you are giving jQuery the wrong values. The fix should not require you to change jQuery, otherwise the IE version of your script will simply have less features (since the incorrect values are simply discarded rather than set correctly).

    I run into this problem and it was both because IE’s default for margins is ‘auto’, and for borders its ‘medium’.

    If you’re going to be using these values, be sure to set them first (in JS, or the CSS/HTML) or don’t assume they will be numerical!.

    I used:
    margin: 0;
    border-width: 0;
    On the div in question and it was all smooth saling from then on.

  8. This still turns up as a problem even now 05.03.2010 with jquery 1.4.2 !

    Big heads up to dave that works !

    At line 4618 let it be so

    try{style[ name ] = value;} catch (error){};

  9. and for info if using the minified version

    line 116 change
    f[b]=d;
    to
    try{f[b]=d;}catch (error){};

Leave a Reply

Your email address will not be published. Required fields are marked *