/    Sign up×
Community /Pin to ProfileBookmark

Assign Javascript values to HTML attributes

Hi,

one more question: how can I assign a return value of a Javascript function to an HTML attribute??

What I’m trying to do is to set the height of a table to a certain value depending on the total height of the browser frame – it should look similiar to this:

<table height=”javascript:function()”>

How does it work???

Alex

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 10.2006 — onload = function(){

var myTab = document.getElementById('mytable');

myTab.style.height=[I]somenumber[/I]+'px';

}
Copy linkTweet thisAlerts:
@bezo360Mar 10.2006 — ---DAMN, Kor beat me to the Submit button!!! --- (and was much more helpful ? )

One thought is to run the function onLoad, then use the style properties to set the table height.

So give your table an ID="whatever" tag then add to your function something like this:

document.whatever.style.height = xyz;

Be warned tho - the height attribute on a table element is anything but consistent - works better on a DIV.
×

Success!

Help @mauroalberti spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...