#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    4
    Rep Power
    0

    Javascript problem by use of PHP - need help !


    Hi guys,

    I'm currently trying to make a little of design around a PHP output page.
    My problem is quite simple but I can't figure an issue.
    I use a javascript to determine the height of a cell containing a variable output generated through PHP:
    <script language="javascript">
    function changeheight() {
    var cellheight;
    if (document.all&&!document.getElementById) {
    cellHeight=document.all.tc1.clientheight;
    document.all.img1.height=cellheight;
    }
    if (document.getElementById) {
    cellheight=(document.all)?document.getElementById("tc1").clientheight:document.getElementById("img1" ).offsetheight;
    document.getElementById("img1").height=cellheight;
    }

    }
    </script>
    Then in my body, I want to stretch the height of two images accordingly to the height of my PHP output cell:
    <tr>
    <td><img src="img/common/pixel_orange.jpg" id="img1" width="1" border="0" onload="changeheight()"></td>
    <td id="tc1"><font size=1><? echo $detail; ?></font></td>
    <td><img src="img/common/pixel_orange.jpg" id="img1" width="1" border="0" onload="changeheight()"></td>
    </tr>
    But it doesn't work !!! Because at the beginning of the script my output cell height is not defined yet.
    Does anyone know how to workaround that problem so that the code sequence would be :
    1. PHP output height defined
    2. Get that damn' height by Javascript or anything else
    3. Stretch the image height to that damn' height
    Thanks a lot for any help !
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    4
    Rep Power
    0

    Answer found (partially at least)...


    Well, the only way I've found is to include my image in the background of <td>... so exit the Javascript.
    Surely it won't work for all browser, but at least it's ok for IE 5 and Netscape 7...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Warrington, UK
    Posts
    56
    Rep Power
    12
    <style>
    #tc1
    {
    position: absolute;
    visibility: hidden;
    }
    </style>

    <span id="tc1">
    <font size=1><? echo $detail; ?></font>
    </span>

    <td><img src="img/common/pixel_orange.jpg" id="img1" width="1" border="0" onload="changeheight()"></td>
    <td><font size=1><? echo $detail; ?></font></td>

    --------------
    Basically, i haven't tried anything like this before, but the idea is that since you need to know the height of the php output first, you display it first on the web page before calling the javascript function, BUT, it is hidden so you won't see it.

    Have a go, and play around with it. It is just CSS-Positioning.
    (EA Development)
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    4
    Rep Power
    0
    Hey, nice idea you've got, I haven't thought to play with that yet.
    Thanks a lot.

IMN logo majestic logo threadwatch logo seochat tools logo