SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Erratic Javascript Error

    I have a bit of JavaScript code that is acting pretty weirdly.

    It works fine in Opera and Mozilla 0.9.9, but it produces an error in most Internet Explorers. Out of 3 Internet Explorers, all version 6 running on Windows XP, one doesn't give an error and the rest do.

    The error in IE is this:
    Code:
    Line: 14
    Char: 3
    Error: Invalid argument
    Code: 0
    URL: http://aboutpcs.com/doc/template4.html
    Here is the code in question, but I think that this error might be happening in several places.

    Code:
    function initial_font_size() {
    	var sizecookie = getCookie("fontsize");
    	
    	if(isNaN(sizecookie) == 0) {
    		document.getElementById("content").style.fontSize = sizecookie + "%"; 
    /* ^^ LINE 14 ABOVE ^^ */
    	} else {
    		document.getElementById("content").style.fontSize = "100%";
    	}
    	
    }
    You can see the whole code at http://aboutpcs.com/doc/template4.html . As far as I can tell, the rest of the JS code works perfectly.

    So, anyone have any ideas? This is my first try at JS, so please don't laugh.

    Thanks!!

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No laughing needed, That is a good idea. I tried to 'break' it. I couldn't do it. I looked at the code and couldn't find anything inherently wrong either.

    Using Ie6 and win2k.

    I will give a shot from work where I have ie5 5.5 and 6 loaded on several different machines
    Last edited by Maelstrom; May 18, 2002 at 00:07.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually it's not weird at all. You get a null value when getting the cookie thats all

    PHP Code:
      function initial_font_size()
      {
        var 
    sizecookie getCookie("fontsize");

        if(
    isNaN(sizecookie) == 0)
        {
          if ( 
    sizecookie == '' || sizecookie == nullsizecookie 100;
          
    document.getElementById("content").style.fontSize sizecookie "%";
        }
        else if (
    sizecookie == '' || sizecookie == null)
        {

        }
        else
        {
          
    document.getElementById("content").style.fontSize "100%";
        }
      } 

  4. #4
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you! It works perfectly now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •