retrieving cell width w/o using eventhandlers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lan Vuong

    retrieving cell width w/o using eventhandlers

    Hi everyone,

    I'm trying to retrieve the width of a cell as the table is being
    dynamically created and add it to a total. I can get the width from
    an eventhandler such as:

    <td onmouseover="al ert(this.width) ;">

    but I don't want to require any user action.

    I've tried using various statements from this newsgroup but none of
    them have worked. Here's a summary of what I've tried:

    document.all.ce llName.width -> % rather than pixel
    document.all.ce llName.offsetWi dth -> 0
    document.getEle mentById('cellI d').width -> 0
    document.getEle mentById('cellI d').style.width -> 0

    Please let me know if you have other suggestions.

    Thanks.
  • mscir

    #2
    Re: retrieving cell width w/o using eventhandlers

    Lan Vuong wrote:[color=blue]
    > Hi everyone,
    > I'm trying to retrieve the width of a cell as the table is being
    > dynamically created and add it to a total. I can get the width from
    > an eventhandler such as:
    > <td onmouseover="al ert(this.width) ;">
    > but I don't want to require any user action.
    > I've tried using various statements from this newsgroup but none of
    > them have worked. Here's a summary of what I've tried:
    > document.all.ce llName.width -> % rather than pixel
    > document.all.ce llName.offsetWi dth -> 0
    > document.getEle mentById('cellI d').width -> 0
    > document.getEle mentById('cellI d').style.width -> 0
    > Please let me know if you have other suggestions.
    > Thanks.[/color]

    Give this.offsetWidt h a try, I found it using code (modified) from this
    page, to see which of an object's properties might be retreived:



    function dumpProps(targe tID) {
    var s1='';
    var msg='';
    obj=document.ge tElementById(ta rgetID);
    for (var i in obj) {
    if (parent) {
    msg = document + "." + i + "------------" + obj[i];
    } else {
    msg = i + "\n" + obj[i];
    }
    s1+='\n'+msg;
    }
    document.getEle mentById('span1 ').innerText=s1 ;
    }

    <table border="1" cellspacing="1" width="60%">
    <tr>
    <td width="33%"
    onmouseover="al ert(this.offset Width)"><span>m ouseover cell</span></td>
    <td width="33%" id="td1" name="td1">targ et cell</td>
    <td width="34%">&nb sp;</td>
    </tr>
    </table>
    <p>&nbsp;
    <span name="span1" id="span1"></span>
    <input type="button" value="show properties" onclick="dumpPr ops('td1')">

    Mike

    Comment

    • Lan Vuong

      #3
      Re: retrieving cell width w/o using eventhandlers

      Hi Mike,

      Thanks for the input but I need to get the cell size w/o having user
      mouseover the cell. I'm creating the table dynamically so I need to
      know when to start a new row by using the window width and cell size.

      Any other ideas?

      Thanks.

      mscir <mscir@access4l ess.com.net.org .uk> wrote in message news:<108ttunre 02ara6@corp.sup ernews.com>...[color=blue]
      > Lan Vuong wrote:[color=green]
      > > Hi everyone,
      > > I'm trying to retrieve the width of a cell as the table is being
      > > dynamically created and add it to a total. I can get the width from
      > > an eventhandler such as:
      > > <td onmouseover="al ert(this.width) ;">
      > > but I don't want to require any user action.
      > > I've tried using various statements from this newsgroup but none of
      > > them have worked. Here's a summary of what I've tried:
      > > document.all.ce llName.width -> % rather than pixel
      > > document.all.ce llName.offsetWi dth -> 0
      > > document.getEle mentById('cellI d').width -> 0
      > > document.getEle mentById('cellI d').style.width -> 0
      > > Please let me know if you have other suggestions.
      > > Thanks.[/color]
      >
      > Give this.offsetWidt h a try, I found it using code (modified) from this
      > page, to see which of an object's properties might be retreived:
      >
      > http://www.breakingpar.com/bkp/home....256BF8004D72D6
      >
      > function dumpProps(targe tID) {
      > var s1='';
      > var msg='';
      > obj=document.ge tElementById(ta rgetID);
      > for (var i in obj) {
      > if (parent) {
      > msg = document + "." + i + "------------" + obj[i];
      > } else {
      > msg = i + "\n" + obj[i];
      > }
      > s1+='\n'+msg;
      > }
      > document.getEle mentById('span1 ').innerText=s1 ;
      > }
      >
      > <table border="1" cellspacing="1" width="60%">
      > <tr>
      > <td width="33%"
      > onmouseover="al ert(this.offset Width)"><span>m ouseover cell</span></td>
      > <td width="33%" id="td1" name="td1">targ et cell</td>
      > <td width="34%">&nb sp;</td>
      > </tr>
      > </table>
      > <p>&nbsp;
      > <span name="span1" id="span1"></span>
      > <input type="button" value="show properties" onclick="dumpPr ops('td1')">
      >
      > Mike[/color]

      Comment

      • mscir

        #4
        Re: retrieving cell width w/o using eventhandlers

        Lan Vuong wrote:[color=blue]
        > Hi Mike,
        >
        > Thanks for the input but I need to get the cell size w/o having user
        > mouseover the cell. I'm creating the table dynamically so I need to
        > know when to start a new row by using the window width and cell size.
        >
        > Any other ideas?
        > Thanks.[/color]

        Please don't top post, it screws up the Q&A flow. Post your code that
        generates the table.
        Mike

        Comment

        • Lan Vuong

          #5
          Re: retrieving cell width w/o using eventhandlers

          mscir <mscir@access4l ess.com.net.org .uk> wrote in message news:<1092h338c kcap93@corp.sup ernews.com>...[color=blue]
          > Lan Vuong wrote:[color=green]
          > > Hi Mike,
          > >
          > > Thanks for the input but I need to get the cell size w/o having user
          > > mouseover the cell. I'm creating the table dynamically so I need to
          > > know when to start a new row by using the window width and cell size.
          > >
          > > Any other ideas?
          > > Thanks.[/color]
          >
          > Please don't top post, it screws up the Q&A flow. Post your code that
          > generates the table.
          > Mike[/color]

          Hi Mike,

          I apologize for the delayed reply. I got pulled away to work on
          something else and I'm just getting back to this code. I've included
          some sample code below that demonstrates what I'm trying to do. I can
          only get the table cell width once the table has been completely
          generated but I'm trying to get it as I'm generating the cells/rows.
          Please let me know if you have any other suggestions.

          Thanks,
          Lan

          <html>
          <script>
          function dumpProps(targe tID) {
          alert('dumpProp s');
          var s1='';
          var msg='';
          obj=document.ge tElementById(ta rgetID);
          for (var i in obj) {
          if (parent) {
          msg = document + "." + i + "------------" + obj[i];
          } else {
          msg = i + "\n" + obj[i];
          }
          s1+='\n'+msg;
          }
          document.writel n(s1);
          }
          </script>
          <table>
          <tbody>
          <tr>
          <td onmouseover="al ert(this.offset Width)" id="test"><a id="link"
          href="#">Dynami cCluster_A</a></td>
          <script>
          //this section returns zero
          alert('offsetWi dth=' + document.getEle mentById("test" ).offsetWidth);
          alert('clientWi dth=' + document.getEle mentById('test' ).clientWidth);
          </script>
          </tr>
          </tbody>
          </table>
          <script>
          //this section returns the correct value
          alert('offsetWi dth=' + document.getEle mentById("test" ).offsetWidth);
          alert('clientWi dth=' + document.getEle mentById('test' ).clientWidth);
          </script>
          </body>
          </html>

          Comment

          Working...