Results 1 to 3 of 3

Thread: cross browser probs with a bit of javascript

  1. #1
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question cross browser probs with a bit of javascript

    Hi All,

    I'm new here, so go gentle

    I have some javascript controlling a DIV box with a border that is inside a table TD, the javascript gets the TD Height as this is expanding all the way to the bottom, and in turn sets the DIV height. however not in Firefox.

    I'm not 100% sure but by looking at the javascript below are there problems with this that are causing the reason it is not working in firefox, and can anyone help me with how to correct this please?

    Or if someone has any suggestions of how to do this differently maybe!

    You can see the box i'm on about here
    HTML Code:
    http://77.99.9.177/cartridge/
    on the left underneath shopping cart with browse by category at the top.

    thanks in advance

    Code:
    <script type="text/javascript" charset="utf-8"> 
    		
    function getTDHeight(){
    contentTop = getPixelsFromTop(document.getElementById("menuN2"))
    contentBottom 	= getPixelsFromTop(document.getElementById("content_bottom"))
    
    heightOfCell = contentBottom - contentTop;
    Newheight = heightOfCell -120
    				
    document.getElementsByName("surround")[0].style.height = Newheight;
    }
    
    function getPixelsFromTop(obj){
    objFromTop = obj.offsetTop;
    while(obj.offsetParent!=null) {
    objParent = obj.offsetParent;
    objFromTop += objParent.offsetTop;
    obj = objParent;
    }
    return objFromTop;
    }
    </script>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Though considered valid according to standards, the charset attribute is never, in my experience used, so could be a problem. Your function should be:

    Code:
    function getTDHeight(){
    var contentTop = getPixelsFromTop(document.getElementById("menuN2")),
    contentBottom 	= getPixelsFromTop(document.getElementById("content_bottom")),
    
    heightOfCell = contentBottom - contentTop,
    Newheight = heightOfCell -120;
    				
    document.getElementsByName("surround")[0].style.height = Newheight + 'px';
    }
    The most important change being the addition of + 'px' to the style property's value setting. This is because units are required in style dimensions, though IE will sometimes ignore this rule.

    There could be other problems.

    Added Later:

    There ia another problem. There is no:

    document.getElementsByName("surround")[0]

    on the page. Use:

    document.getElementById("surround")

    That exists (from your source code):

    Code:
                       
    				<!-- START CATEGORY BOX -->
    
         <div id="surround">
        <img src='images/menu/browse.gif' alt='Browse by category' width='117' height='27'/>
    <table width="150" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="10"><img src="images/menu/cross.gif" alt="cross" width="6" height="6" /></td>
        <td class="title">BROTHER</td>
      </tr>
    </table>
    
    
    <table width="150" border="0" cells . . .
    There still could be other issues.
    Last edited by jscheuer1; 09-30-2008 at 03:59 PM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wink

    perfect my friend...thank you very much, i really appreciate your effort. those were the bugs working fine 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
  •