Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Shrinking the width of a WIDTH=100% table

Reply
Thread Tools

Shrinking the width of a WIDTH=100% table

 
 
Swifty
Guest
Posts: n/a
 
      01-20-2012
I have a CGI script that builds a table with "WIDTH=100%"

There are many paths through the code, but they all required the table
to be WIDTH=100%

Now, I find that in just one of the paths, it would be better if that
WIDTH=100% had not been specified.

Is there any JavaScript that I can insert, after the <TABLE> has
already been started, which will remove the effect of the WIDTH=100%

I'm open to a CSS solution as well, but there are other tables in the
same page which must remain WIDTH=100% so it would have to be specific
to just this one table.

N.B. My environment ensures that all users will have JavaScript
enabled.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
 
Reply With Quote
 
 
 
 
Captain Paralytic
Guest
Posts: n/a
 
      01-20-2012
On Jan 20, 2:04*pm, Swifty <(E-Mail Removed)> wrote:
> I have a CGI script that builds a table with "WIDTH=100%"
>
> There are many paths through the code, but they all required the table
> to be WIDTH=100%
>
> Now, I find that in just one of the paths, it would be better if that
> WIDTH=100% had not been specified.
>
> Is there any JavaScript that I can insert, after the <TABLE> has
> already been started, which *will remove the effect of the WIDTH=100%
>
> I'm open to a CSS solution as well, but there are other tables in the
> same page which must remain WIDTH=100% so it would have to be specific
> to just this one table.
>
> N.B. My environment ensures that all users will have JavaScript
> enabled.
>
> --
> Steve Swifthttp://www.swiftys.org.uk/swifty.htmlhttp://www.ringers.org.uk


Why not alter it in that one specific path through the cgi code?
 
Reply With Quote
 
 
 
 
Jukka K. Korpela
Guest
Posts: n/a
 
      01-20-2012
2012-01-20 16:04, Swifty wrote:

> Is there any JavaScript that I can insert, after the <TABLE> has
> already been started, which will remove the effect of the WIDTH=100%


Yes. I suppose you have considered the obvious solution of not writing
WIDTH=100% for a specific table, and I suppose the reason for rejecting
that idea is in the logic of your server-side code: you're in the midst
of writing data when you find out that something should have been done
earlier.

Using JavaScript, you could change the width property of the <table>
element. For this, you could e.g. emit an empty <span> element with an
id so that appears inside a cell of the table, then traverse the
document tree upwards until you find the <table> element:

<table width="100%" border>
<tr><td>Hello world <td>Hello again
<tr><td>Foo <td> Bar
<span id="foo"></span>
<script>
var el = document.getElementById('foo');
do {
el = el.parentNode;
} while (el.tagName != 'TABLE');
el.width = '';
</script>
</table>

(So the <span> and <script> elements are what you would need to add to
the generated markup. The identifier 'foo' can be anything as long as it
is unique within the document.)

> I'm open to a CSS solution as well, but there are other tables in the
> same page which must remain WIDTH=100% so it would have to be specific
> to just this one table.


You cannot validly emit CSS code that would affect the table that has
been started. No style attribute can do that. A <style> element would,
but it's invalid in <body> (though browsers allow it, to the extent that
it might even be declared a feature). And to make a CSS rule apply to a
specific table, you would probably need a class attribute on it, but I
suppose it would be too late to emit one.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
Erwin Moller
Guest
Posts: n/a
 
      01-20-2012
On 1/20/2012 4:04 PM, Jukka K. Korpela wrote:
> 2012-01-20 16:04, Swifty wrote:
>
>> Is there any JavaScript that I can insert, after the <TABLE> has
>> already been started, which will remove the effect of the WIDTH=100%

>
> Yes. I suppose you have considered the obvious solution of not writing
> WIDTH=100% for a specific table, and I suppose the reason for rejecting
> that idea is in the logic of your server-side code: you're in the midst
> of writing data when you find out that something should have been done
> earlier.
>
> Using JavaScript, you could change the width property of the <table>
> element. For this, you could e.g. emit an empty <span> element with an
> id so that appears inside a cell of the table, then traverse the
> document tree upwards until you find the <table> element:
>
> <table width="100%" border>
> <tr><td>Hello world <td>Hello again
> <tr><td>Foo <td> Bar
> <span id="foo"></span>
> <script>
> var el = document.getElementById('foo');
> do {
> el = el.parentNode;
> } while (el.tagName != 'TABLE');
> el.width = '';
> </script>
> </table>


Why not simply give the table an id and use that?

Regards,
Erwin Moller


--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      01-20-2012
2012-01-20 17:35, Erwin Moller wrote:

> On 1/20/2012 4:04 PM, Jukka K. Korpela wrote:

[...]
>> I suppose you have considered the obvious solution of not writing
>> WIDTH=100% for a specific table, and I suppose the reason for rejecting
>> that idea is in the logic of your server-side code: you're in the midst
>> of writing data when you find out that something should have been done
>> earlier.

[...]
> Why not simply give the table an id and use that?


Because you cannot do that when you have already generated the <table>
tag and a few rows.
Or, you could do that by operating in the document tree, but this would
be just
a more complicated version of doing what I suggested.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
Swifty
Guest
Posts: n/a
 
      01-20-2012
On Fri, 20 Jan 2012 16:35:43 +0100, Erwin Moller
<(E-Mail Removed)> wrote:

>Why not simply give the table an id and use that?


I couldn't have put that better myself. I'll explain a little further
(albeit still simplified):

At the beginning of my CGI, I create the table. There are other tables
making up the header and the footer, but the body of the table
contains only the one. THE table. After the table has started, the
code can take myriad paths, resulting in different rows. One of these
paths would look better without the WIDTH=100%

So I can easily make this something like:

<TABLE WIDTH=100% ID=Body_Table>

Presumably I need some GetElementByID call, and then I'll be all set.

I have a GetElementByID call somewhere in the pages that I look after;
I'll use that as my working example.

I've had too good a day to risk spoiling it by an utter failure in my
JavaScript, but I'll try it over the weekend.

Today:

1. My dog, Nelly, found my bluetooth earpiece that I lost yesterday,
about 800m away from where I live. http://www.swiftys.org.uk/blog

2. I found the fragment of the tooth that broke four days ago. I
thought that I must have swallowed it, and was worried that it might
do me some harm. I had swallowed it. I won't go into further details.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-20-2012
Swifty wrote:

> I have a CGI script that builds a table with "WIDTH=100%"


First of all, CGI is an obsolete technology [1]. Use server extensions or
FastCGI [2] instead.

> There are many paths through the code, but they all required the table
> to be WIDTH=100%


Second, do not do that. Learn and apply CSS instead [3].

> Now, I find that in just one of the paths, it would be better if that
> WIDTH=100% had not been specified.
>
> Is there any JavaScript that I can insert, after the <TABLE> has
> already been started, which will remove the effect of the WIDTH=100%


Since the `width' attribute has no specified default value [4], the only
proper way is to program what you would do manually: remove the attribute.

elem.removeAttribute("width");

However, if you had used CSS, you could have reset the `width' property to
its specified initial value [3, 5]:

elem.style.width = "auto";


PointedEars
___________
[1] <http://en.wikipedia.org/wiki/Common_Gateway_Interface#Drawbacks>
[2] <http://www.fastcgi.com/drupal/>
[3] <http://www.w3.org/TR/CSS21/visudet.html#propdef-width>
[4] <http://www.w3.org/TR/html4/struct/tables.html#adef-width-TABLE>
[5] <http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties>
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
Swifty
Guest
Posts: n/a
 
      01-21-2012
On Fri, 20 Jan 2012 22:17:02 +0100, Thomas 'PointedEars' Lahn
<(E-Mail Removed)> wrote:

>However, if you had used CSS, you could have reset the `width' property to
>its specified initial value [3, 5]:
>
> elem.style.width = "auto";


I'm happy to convert to CSS if that helps. It means having to make two
changes, where perhaps one change would have been sufficient. I'm
under time constraint... I have only 363 working days left in my
career.

So, as you see, CGI is an appropriate obsolete technology for me, as
both I and my skill will be obsolete next year.

I'm going for a record in the IT industry. When I joined the company
that I work for in 1976, the programming language that I use was in
the early stages of its development, and some of my suggestions were
incorporated. I've now been programming in that language for 35 years
and 26 days; effectively doing the same job throughout that time.

This, for me, is the attraction of building webpages with CGI. It
hardly matters what programming language you use.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      01-21-2012
Swifty wrote on 21 jan 2012 in comp.lang.javascript:

> On Fri, 20 Jan 2012 22:17:02 +0100, Thomas 'PointedEars' Lahn
> <(E-Mail Removed)> wrote:
>
>>However, if you had used CSS, you could have reset the `width'
>>property to its specified initial value [3, 5]:
>>
>> elem.style.width = "auto";

>
> I'm happy to convert to CSS if that helps. It means having to make two
> changes, where perhaps one change would have been sufficient. I'm
> under time constraint... I have only 363 working days left in my
> career.
>
> So, as you see, CGI is an appropriate obsolete technology for me, as
> both I and my skill will be obsolete next year.
>
> I'm going for a record in the IT industry. When I joined the company
> that I work for in 1976, the programming language that I use was in
> the early stages of its development, and some of my suggestions were
> incorporated. I've now been programming in that language for 35 years
> and 26 days; effectively doing the same job throughout that time.
>
> This, for me, is the attraction of building webpages with CGI. It
> hardly matters what programming language you use.


While I grand you your personal hobbies in your career,
you do not respond on the part of PE's posting you quote above.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-21-2012
Swifty wrote:

> Thomas 'PointedEars' Lahn wrote:
>> However, if you had used CSS, you could have reset the `width' property
>> to its specified initial value [3, 5]:
>>
>> elem.style.width = "auto";

>
> I'm happy to convert to CSS if that helps. It means having to make two
> changes, where perhaps one change would have been sufficient. I'm
> under time constraint... I have only 363 working days left in my
> career.


Please read my posting again, and whole this time.

> [snipped autobiography]



PointedEars
--
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...

Not with javascript. Nonsense propagates like wildfire in this field.
-- Richard Cornford, comp.lang.javascript, 2011-11-14
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
picture width decides table column width David Basford HTML 3 09-30-2007 10:49 PM
Textbox width scaling to width of data not width of page? AndrewF ASP .Net 1 10-10-2005 04:38 PM
Web page width is shrinking/scrunching on some machines Eric ASP .Net 4 06-30-2004 03:18 PM
Table width and columns width kris HTML 11 11-18-2003 06:49 AM
Re: resized image in table extends table width to original image width Sean Jorden HTML 1 08-19-2003 08:59 AM



Advertisments