SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Script edit... now doesn't work.

    Help... No one seems to be able to and answer this one, so I found another script and editted it a little.

    Modified Code:
    Code:
    var state = 'none'; 
    var class = 'IE-CONTENT-CLOSED';
    
    function showhide(layer_ref, layer_header) { 
    
    if (state == 'block') { 
    state = 'none'; 
    class = 'IE-CONTENT-CLOSED';
    } 
    else { 
    state = 'block'; 
    class = 'IE-CONTENT-OPEN';
    } 
    if (document.all) { //IS IE 4 or 5 (or 6 beta) 
    eval( "document.all." + layer_ref + ".style.display = state"); 
    eval( "document.all." + layer_header + ".className = class"); 
    } 
    if (document.layers) { //IS NETSCAPE 4 or below 
    document.layers[layer_ref].display = state; 
    document.layers[layer_header].className = class; 
    } 
    if (document.getElementById &&!document.all) { 
    hza = document.getElementById(layer_ref); 
    hya = document.getElementById(layer_header);
    hza.style.display = state; 
    hya.className = class;
    } 
    }
    Original Code:

    Code:
    var state = 'none'; 
    
    function showhide(layer_ref) { 
    
    if (state == 'block') { 
    state = 'none'; 
    } 
    else { 
    state = 'block'; 
    } 
    if (document.all) { //IS IE 4 or 5 (or 6 beta) 
    eval( "document.all." + layer_ref + ".style.display = state"); 
    } 
    if (document.layers) { //IS NETSCAPE 4 or below 
    document.layers[layer_ref].display = state; 
    } 
    if (document.getElementById &&!document.all) { 
    hza = document.getElementById(layer_ref); 
    hza.style.display = state; 
    } 
    }
    Calling the function:

    With Modification:
    Code:
    <img src="images/shim.gif" width="25" height="17" border="0" onClick="showhide('Main','Main_Header');">
    WIthout Modification:
    <img src="images/shim.gif" width="25" height="17" border="0"
    Code:
    onClick="showhide('Main');">
    HTML Code:
    Code:
    <table width="580" border="0" align="center" cellpadding="0" cellspacing="0" class="IE-TABLEGENERIC">
                        <tr> 
                          <td class="IE-CONTENT-OPEN" id="Main_Header"><table width="560" border="0" align="right" cellpadding="0" cellspacing="0" class="IE-TABLEGENERIC">
                              <tr> 
                                <td><img src="images/shim.gif" alt="shim" width="5" height="5" /></td>
                                <td width="5"><img src="images/shim.gif" alt="shim" width="5" height="5" /></td>
                                <td width="25"><img src="images/shim.gif" alt="shim" width="5" height="5" /></td>
                              </tr>
                              <tr> 
                                <td width="560"><strong>Test</strong></td>
                                <td>&nbsp;</td>
                                <td><a href="#"><img src="images/shim.gif" width="25" height="17" border="0" onClick="showhide('Main','Main_Header');"></a></td>
                              </tr>
                            </table></td>
                        </tr>
                      </table>
                      <table width="580" border="0" align="center" cellpadding="0" cellspacing="0" class="IE-TABLEGENERIC" id="Main">
                        <tr>
                          <td class="IE-CONTENT-BG"><table width="550" border="0" align="center" cellpadding="0" cellspacing="0" class="IE-TABLEGENERIC">
                              <tr> 
                                <td>test</td>
                              </tr>
                            </table>
                          </td>
                        </tr>
                      </table>
                      <table width="580" border="0" align="center" cellpadding="0" cellspacing="0" class="IE-TABLEGENERIC">
                        <tr> 
                          <td><img src="images/infobox_btm.jpg" alt="Content Bottom" width="580" height="10"></td>
                        </tr>
                      </table>
    I'm getting Object required errors on the modified version, but I need to change the class of the header so it tells people that its closed or open.

    Error :

    Line: 86
    Char: 1
    Error: Object expected
    Code: 0
    URL: http://www.eycdwebdesign.co.uk/v2/

    You can view the site at:

    http://www.eycdwebdesign.co.uk/v2/

    Can anyone help?

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're missing an opening SCRIPT tag before this line:

    var state = 'none';

  3. #3
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just put the script inbetween the

    <script language="JavaScript" type="text/javascript" src="cgi-bin/includes/IEJS.js">
    </script>

    tag.

    But I changed this and I am still getting the same error but different line ( only because I have added script to the page )

    Anyone else?

    Gav

  4. #4
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well its a tad hard to see what you're trying to do here but I did notice you are sending two variables in your new onclick call to the method:

    onClick="showhide('Main','Main_Header');"

    whereas your method is only accepting one variable so I think your confusing the heck out of the browser ..... there are no actual javascript errors in FF but I dont really see anything happening either (except a small amount of movement in the second word test)

    I also see table #2 has the ID of Main but a TD cell in the 1st table has the ID of Main_Header

    Needless to say I think you're going to have to explain what your trying to do a little better for us to help.

  5. #5
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol usually I get told I explain my problems too well....

    anyhoo.. Basically what im trying to do is hide a table, and then change the
    background of a column. So I have created two css styles, one on and one off.

    So when the use clicks, it hides the table marked as Main, and then changes the table columns background marked as Main_Header.. providing I am calling

    onClick="showhide('Main','Main_Header');"

    It seems there is a problem with the script as when I leave it like this:

    Code:
    <script language="JavaScript" type="text/javascript">
    
    var state = 'none'; 
    var class = 'IE-CONTENT-OPEN';
    
    function showhide(layer_ref) { 
    
    if (state == 'block') { 
    state = 'none'; 
    } 
    else { 
    state = 'block'; 
    }
    if (document.all) { //IS IE 4 or 5 (or 6 beta) 
    eval( "document.all." + layer_ref + ".style.display = state"); 
    } 
    if (document.layers) { //IS NETSCAPE 4 or below 
    document.layers[layer_ref].display = state; 
    } 
    if (document.getElementById &&!document.all) { 
    hza = document.getElementById(layer_ref); 
    hza.style.display = state; 
    } 
    }
    </script>
    But if I remove the new var, it works fine ( obviously without changing the column's class )

    I tried calling it a different name just incase it was reserved, and still nothing.

    HELP!!!

    Thanks

    Gav

  6. #6
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well finally got it working, found a javascript validator, it pointed out any errors that could possibly happen as IE was pointing to line 1 char 1, loads of help?!

    I suggest downloading: Scryptik

    Rather then a true validator, it actually parses the file, and outputs what errors it finds in a seperate box.

    Thanks to all... Now a new post..

    Gav

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dc dalton
    ...I did notice you are sending two variables in your new onclick call to the method:

    onClick="showhide('Main','Main_Header');"

    whereas your method is only accepting one variable so I think your confusing the heck out of the browser
    Welcome to javascript:
    Code:
    var sum1 = calc_total(10, 20, 30);
    alert(sum1);
    
    var sum2 = calc_total(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    alert(sum2);
    
    function calc_total()
    {
    	var total = 0;
    	for(var i = 0, len = arguments.length; i < len; i++)
    	{
    		total += arguments[i];
    	}
    
    	return total;
    }

  8. #8
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I know and that makes me CRAZY that js does that.

    Im a Java programmer by trade so I always code my javascript just like java. If I dont I start writing the wrong code in the wrong prog ....... makes other js programmers nutzo but if I dont keep to the strict rules of java I start REALLY screwing up my Java.

    funny I just finished 3 days of javascript and then had to jump over to some servlet stuff and java objects....... I must have caught myself typing "var something" a hundred times today in Java ....... needless to say there was a LOT of "YOU IDIOT" coming out of my office all day long!

  9. #9
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what made it worse, is that IE is so crap that it doesn't actually report any errors unless they are 'STUPID IDIOT' simple. How the hell are you meant to troubleshoot error on

    Line: 1
    Char: 1

    Erm no javascript there lol

    but I used a prog that parses the script and outputs the errors, how to fix them, what line, and it highlights it...

    Some reason I am unable to use the script in an external js file.. when I do it says object expected and it points to the link that is calling it.

    Any ideas why?

    Gav

  10. #10
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you linking it correctly? I think I had that problem before.

    HTML Code:
    <script src="whatever.js" type="text/javascript"> </script>

  11. #11
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    erm... I hope so otherwise my other js scripts wont work lol...

  12. #12
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you indeed have js errors the web dev bar for Firefox will give you better information on them ..... a javascript error is a javascript error, no matter what browser its in ...... BUT if you are using a chunk of code that IE may not recognize or support then the "fun" problems begin ....

    that usually only happens when you are trying to do inner html switchs and things like that BUT if you stick with standardized stuff you SHOULD be ok except in older browsers.


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
  •