Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 4th, 2004, 12:33 PM
Authorized User
 
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default calculating <td> width in pixels

Hello,

The problem I have is: how do you get the pixel width of a column in an HTML table which is defined by percentage?

e.g: <td width=30%> </td>

I had a look in a couple of books I own, but there doesnt seem to a function\method to get the width of a column. Any ideas?

Any input and avice is gratefully recieved!

Morris


 
Old June 5th, 2004, 02:07 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

alternatively you can use Style tag or something like
<td width=200>

Om Prakash
 
Old June 5th, 2004, 07:38 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

om_prakash:

Using percent widths is more compatable when the client is resizing the window. They always take up x percent of the window/available space. Usually not adding a suffix to a width (i.e. 'px', '%', 'in') defaults to px anyway.

HTH,

Snib

<><
 
Old June 6th, 2004, 04:30 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Snib,
 Yes i do agree with you, as '%' gives more options and control.

Om Prakash
 
Old June 8th, 2004, 10:39 AM
Authorized User
 
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey!

Firstly, sorry for not replying sooner.

Secondly, thanks for the advice, however it is not quite what i am looking for.

The reason I want to find the width of a column is so I can define the starting position of a drop down navigation bar and align it with the starting position of a banner.

By using % i have been able to create a site which is more 'user friendly' when the client window is resized.

But, at the moment, my naviagtion bar is defined by static coordinates - eg: (130, 109).

So, when the window is resized, the html elements will adjust, but the nav bar wont move with it.

Any ideas about how i can make the nav bar starting position adjust to changes in the window size in the smae way the html elements do?

Many thanks,

Morris

 
Old June 8th, 2004, 10:44 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

If I understand correctly, why don't you just define the nav bar with '%'?

Snib

<><
 
Old June 8th, 2004, 11:29 AM
Authorized User
 
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I still need to define the starting point of the nav bar:

e.g: the starting point is defined in the code by
     myNavBar1.moveTo(130, 109);

Because the start point of the name bar is defined statically in code, the start position of the nav bar will never move from (130,109), regardless of the width of the nav bar.

Thanks,

Morris

 
Old June 8th, 2004, 12:30 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Morris,

You could use offsetWidth with *most* browsers, something like...

<html>

<head>
<title>Scrap</title>

<script type="text/javascript">
window.onresize = DoResize;
function DoResize(){
    var d = document;
    d.getElementById("NavBar").style.left = d.getElementById("LeftColCell").offsetWidth;
}
</script>

<body onload="DoResize();">

<table style="width: 100%">
    <tr>
        <td id="LeftColCell" style="width: 30%; border: red 1px solid;">left of nav bar</td>
        <td style="width: 70%;">under nav</td>
    </tr>
</table>

<div id="NavBar" style="position: absolute; top: 0px; height: 250px; border: black 1px solid; background-color: whitesmoke; width: 150px;">some nav stuff</div>

</body>
</html>


HTH,

Chris

 
Old June 8th, 2004, 04:29 PM
Authorized User
 
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey!

Thanks for the advice, it is really appreciated! However, one small problem, I am looking at my code and I seem to fit your suggestion into it. Here is my code:

Code:
 <script language="JavaScript"src="files/JScriptNavbar/navcond.js"></script>
 <script language="JavaScript">

  var myNavBar1 = new NavBar(0);
  var dhtmlMenu;

  dhtmlMenu = new NavBarMenu(100, 0);
  dhtmlMenu.addItem(new NavBarMenuItem("Home", "index.html"));
  myNavBar1.addMenu(dhtmlMenu);

  dhtmlMenu = new NavBarMenu(100, 120);
  dhtmlMenu.addItem(new NavBarMenuItem("News", ""));
  dhtmlMenu.addItem(new NavBarMenuItem("Weekly Events", "calendar/weekly.html"));
  myNavBar1.addMenu(dhtmlMenu);

  myNavBar1.setColors ("#FFFFFF", "#007AC0", "#C0C0C0", "#FFFFFF", "#666666", "#007AC0", "#cccccc", "#ffffff", "#666666")

  myNavBar1.setAlign("left")

  var fullWidth;
  function init() {
   fullWidth = getWindowWidth() 
    - (isMinNS4 && getWindowHeight() < getPageHeight() ? 16 : 0);

   myNavBar1.resize(745);
   myNavBar1.create();
   myNavBar1.setzIndex(2);

   myNavBar1.moveTo(130, 109);
  }
 </script>
</Head>
<BODY onload="init()">
  <TABLE cellSpacing=0 cellPadding=0>
   <tbody>
    <tr>
     <td width=30% id=col_one>
     </td>
     <td>
      <A href="index.htm">
      <IMG alt="return to the main page." src="images/logo_2.gif">
      </A>
      <br>
      <br>
     </td>
     <td width=30%>
     </td>
    </tr>
   </tbody>
  </table>
</BODY>
All help and suggestions are welcome! Cheers

Morris






Similar Threads
Thread Thread Starter Forum Replies Last Post
Change data of <TD> austinf Javascript 3 July 28th, 2006 05:32 AM
Fixing <TD> size. rupen HTML Code Clinic 4 April 28th, 2006 07:41 AM
change <td> value onClick crmpicco Javascript How-To 2 August 23rd, 2005 07:31 AM
XML into <td> crmpicco Classic ASP Basics 4 February 11th, 2005 09:57 AM
using variables within <td> tags handyman Javascript How-To 3 June 15th, 2004 11:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.