table width

How can I get from javascript the width of a table.

I tried to do it but I didn't get it!!

How can I get it. Because I want to resize a pop-up screen to the width of the table.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

boycey19Connect With a Mentor Commented:
Here's the code you require.


<table id="table1" width="100" height="100">



var width, height;
var browser_name = navigator.appName;
var version = parseInt(navigator.appVersion);

if(browser_name == "Microsoft Internet Explorer" && version >= 4)
  width = document.all.table1.width;
  height = document.all.table1.height;

if(browser_name == "Netscape" && version >= 4)
  width = document.table1.width;
  height = document.table1.height;

document.write("The dimensions of the table are " + width + "x" + height);


I tried this code and it works. I have included the browser sniffer because of the varitaion in the Document Object Model. Remember to use "id" instead of "name" in the table tag, this is so we can refrence it as a JScript Object.  

mkdebontAuthor Commented:

I had the same script only in the table tag I had "name" instead of "id". I didn't find anyting in a javascript book, but it will works like this.

All Courses

From novice to tech pro — start learning today.