Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Oct 2003
    Location
    Ukraine
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why offsetXXX properties are all zero ?

    Hi,

    I've done control in asp.net/javascript and it works on some pages of mine and as it often happens doesn't work on customer's pages .
    All pages are run in IE 6.0.
    After I run debugger I've found out that on my page offsetLeft/Top clientHeight properties have some non-zero values.
    I have <span id="listCLient" style="width:200px;">..</span> and on my test page elListClient.clientHeight = 200, but on customer's app's page it is 0x0 ?
    Same with other offsetXXX properties etc.
    But elListClient.style.height bears correct value.
    I use those properties everywhere.

    I think it is some settings somewhere ? or CSS styles ?
    Can anyone help ?

    Thanks a lot

    Vladislav

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    clientHeight/Width are property of body, not of an object nested in body. Thus in your example I think elListClient.clientHeight is an incorrect syntax.

    If you want to retreive the objects size use

    obj.offsetHeight
    obj.offsetWidth
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Oct 2003
    Location
    Ukraine
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is a dropdownlist control.
    I have 4 elements: textbox (this.elInput), button (this.elButton),
    div (elDropDown) that's hidden, when I press a button it is visible and surronding span object (this.elMain).
    I set size of the textbox based on size of surrounding elMain minus size of a button and then position dropdown beneath textbox and button (they are on one line)
    So I have this code:
    // set width of the text box
    this.elInput.style.width = this.elMain.clientWidth - this.elButton.offsetWidth;
    // position the divDropDown
    this.elDropDown.style.top = this.elMain.offsetTop + this.elInput.offsetHeight;
    this.elDropDown.style.left = this.elMain.offsetLeft;
    this.elDropDown.style.width = this.elMain.clientWidth;

    Syntax is correct becuase it works on my test page and IE 6.0.
    It doesn't work on the production page of my customer - textbox doesn't show only a button. So I asked him to go into a debugger and it appeared that this.elMain.clientWidth = 0,this.elMain.offsetTop = 0, this.elMain.offsetLeft = 0. However control is not at the top of the page and I have style="width:250px;" on span (this.elMain) so clientHeight has not to be a 0. But this.elMain.style.width is "250px".

    Slava

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,946
    Thanks
    0
    Thanked 236 Times in 233 Posts
    It's better that you post the whole code or post a link to visualize the whole thing.

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    New Coder
    Join Date
    Oct 2003
    Location
    Ukraine
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found the reason why properties offsetTop/Left/Width/Height are al zero. That happens when I put my control inside of the table's cell. Only I put it outside of the table all properties have non zero values.
    I'll try to give a link here.

    Thanks

  • #7
    New Coder
    Join Date
    Oct 2003
    Location
    Ukraine
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've found my bug now. I was registering my script that defines my object near my object's html tags. So if I move script to the end of page all is OK.
    Maybe when script was in the table browser didn't finished creating a table and other it's objects and that time I tried to measure them with offsetWidth etc.

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SlavaTT
    Maybe when script was in the table browser didn't finished creating a table and other it's objects and that time I tried to measure them with offsetWidth etc.
    That would be true, until the browser processes the </table> tag it may end up re-arranging the table because some cell's content requires a larger than specified amount of space so it doesn't "fill-in" the position information until it's sure what it'll contain.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #9
    New to the CF scene
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks for your posts on the problem's source. This was a really great help as I had the same problem with script before layout table's end in IE6.


  •  

    Posting Permissions

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