The Dev Pages

A knowledge base for simple (and beyond) web applications development




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

  1. Dom Said,

    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. Ivan Said,

    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. Jesse Said,

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

  4. Brinley Ang Said,

    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. Jamie McDonnell Said,

    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. Chris Haines Said,

    Brinley you’re a genius! Setting margin:0 on the dialog style worked perfectly

  7. Lee Said,

    Wow! Thanks for this post. I was flummoxed over this and now I’m back in action!

  8. Adam Said,

    Brilliant! This was annoying the crap out of me.

  9. Adam Said,

    Also mine was coming up with NaNem

    Look out for that one too.

  10. Jamie McDonnell Said,

    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

  11. Ezequiel Muns Said,

    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.

  12. Dave Said,

    line 1065 and 1002
    elem[ name ] = value;

    change this to
    try{elem[ name ] = value;} catch (error){};

  13. Jaysap Said,

    Simply adding

    *{ border: 0 }

    to your css file fixes it.

  14. Michael Said,

    #12 Dave – Thanks so much man. This fixed my IE7 issues. I want to kiss you

  15. john Said,

    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){};

  16. john Said,

    and for info if using the minified version

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

  17. aavsa Said,

    John thank you very much its worked on ie8

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

Add A Comment