Computing.Net > Forums > Web Development > javascript varying table width

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

javascript varying table width

Reply to Message Icon

Name: timothy_aah
Date: February 23, 2008 at 12:17:42 Pacific
OS: xp/vista
CPU/Ram: AMD X2 4200/2GB
Comment:

hi,

I'm trying to set the width of an element, a table for example by using javascript.
problem is I know hardly anything of javascript
I figured it would have to be something like this:
part in body:

<table width="getwidth();"><tr><td>table content</td></tr></table>

part in head:

<script type="text/javascript">
function getwidth()
{
*code to determine value*;
return *value*;
}
</script>

but apparently this isn't working...
can somebody help me out here?
thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: February 23, 2008 at 15:38:56 Pacific
Reply:

It's better be like this:

<script type="text/javascript">

function setTableWidth() {
var theTable = document.getElementById('theTable');
theTable.style.width = '500px';
}

window.onload = function() {
setTableWidth();
}

</script>
</head>


... and you put the id to the table below


<table id="theTable">
<tr>
...


and if you're going to do lotsa javascripts you can use some popular library like this or this for syntax-simplifying and crossbrowserability.


0

Response Number 2
Name: timothy_aah
Date: February 24, 2008 at 04:16:29 Pacific
Reply:

ok, thx!
works now^^


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: javascript varying table width

Finding string width using PHP/JS www.computing.net/answers/webdevel/finding-string-width-using-phpjs/1919.html

Table Column Width Problem www.computing.net/answers/webdevel/table-column-width-problem/2865.html

javascript and php www.computing.net/answers/webdevel/javascript-and-php/1068.html