473,320 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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="alert(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.cellName.width -> % rather than pixel
document.all.cellName.offsetWidth -> 0
document.getElementById('cellId').width -> 0
document.getElementById('cellId').style.width -> 0

Please let me know if you have other suggestions.

Thanks.
Jul 23 '05 #1
4 1895
Lan Vuong wrote:
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="alert(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.cellName.width -> % rather than pixel
document.all.cellName.offsetWidth -> 0
document.getElementById('cellId').width -> 0
document.getElementById('cellId').style.width -> 0
Please let me know if you have other suggestions.
Thanks.


Give this.offsetWidth 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(targetID) {
var s1='';
var msg='';
obj=document.getElementById(targetID);
for (var i in obj) {
if (parent) {
msg = document + "." + i + "------------" + obj[i];
} else {
msg = i + "\n" + obj[i];
}
s1+='\n'+msg;
}
document.getElementById('span1').innerText=s1;
}

<table border="1" cellspacing="1" width="60%">
<tr>
<td width="33%"
onmouseover="alert(this.offsetWidth)"><span>mouseo ver cell</span></td>
<td width="33%" id="td1" name="td1">target cell</td>
<td width="34%">&nbsp;</td>
</tr>
</table>
<p>&nbsp;
<span name="span1" id="span1"></span>
<input type="button" value="show properties" onclick="dumpProps('td1')">

Mike

Jul 23 '05 #2
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 <ms***@access4less.com.net.org.uk> wrote in message news:<10*************@corp.supernews.com>...
Lan Vuong wrote:
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="alert(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.cellName.width -> % rather than pixel
document.all.cellName.offsetWidth -> 0
document.getElementById('cellId').width -> 0
document.getElementById('cellId').style.width -> 0
Please let me know if you have other suggestions.
Thanks.


Give this.offsetWidth 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(targetID) {
var s1='';
var msg='';
obj=document.getElementById(targetID);
for (var i in obj) {
if (parent) {
msg = document + "." + i + "------------" + obj[i];
} else {
msg = i + "\n" + obj[i];
}
s1+='\n'+msg;
}
document.getElementById('span1').innerText=s1;
}

<table border="1" cellspacing="1" width="60%">
<tr>
<td width="33%"
onmouseover="alert(this.offsetWidth)"><span>mouseo ver cell</span></td>
<td width="33%" id="td1" name="td1">target cell</td>
<td width="34%">&nbsp;</td>
</tr>
</table>
<p>&nbsp;
<span name="span1" id="span1"></span>
<input type="button" value="show properties" onclick="dumpProps('td1')">

Mike

Jul 23 '05 #3
Lan Vuong wrote:
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.


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

Jul 23 '05 #4
mscir <ms***@access4less.com.net.org.uk> wrote in message news:<10*************@corp.supernews.com>...
Lan Vuong wrote:
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.


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


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(targetID) {
alert('dumpProps');
var s1='';
var msg='';
obj=document.getElementById(targetID);
for (var i in obj) {
if (parent) {
msg = document + "." + i + "------------" + obj[i];
} else {
msg = i + "\n" + obj[i];
}
s1+='\n'+msg;
}
document.writeln(s1);
}
</script>
<table>
<tbody>
<tr>
<td onmouseover="alert(this.offsetWidth)" id="test"><a id="link"
href="#">DynamicCluster_A</a></td>
<script>
//this section returns zero
alert('offsetWidth=' + document.getElementById("test").offsetWidth);
alert('clientWidth=' + document.getElementById('test').clientWidth);
</script>
</tr>
</tbody>
</table>
<script>
//this section returns the correct value
alert('offsetWidth=' + document.getElementById("test").offsetWidth);
alert('clientWidth=' + document.getElementById('test').clientWidth);
</script>
</body>
</html>
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hiwj | last post by:
I am having a problem with a cell in a table in ASP.NET which used to work OK in classic ASP. I have one cell in a row where the width should be 22 pixels and the other cell should take up the...
2
by: Iain | last post by:
Hi All Using Delphi 2006 developer - C# Project I have the following 2 event handlers for the datagrid - see botton of page Both events will fire off correctly but i have a problem collecting...
1
by: Manil | last post by:
I usually have no problem with Firefox, but here is a rare instance of IE displaying a table with image slices correctly and Firefox adding space where I seemingly have none. Is there anything I can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.