PDA

View Full Version : despertly need help-getelement by id wont work



genia
07-21-2008, 04:05 PM
function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight)=='number') {
windowHeight=window.innerHeight;
}
else {
if (document.documentElement&&
document.documentElement.clientHeight) {
windowHeight=
document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
return windowHeight;
}
var t
t=getWindowHeight(this)
alert(t)
x=(t-400)
document.getElementById('row4r').style.padding-bottom=x+"px"

Dal
07-21-2008, 04:21 PM
document.getElementById('row4r').style.padding-bottom=x+"px"

Is this the part that wont work?

genia
07-21-2008, 04:50 PM
exactly
checked for case sensitivity and lots of things

blm126
07-21-2008, 04:54 PM
Most likely, the page isn't loaded when you are trying to run that function. I need to see the whole page to be sure. But, if I'm right then try this code and see what happens


function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight)=='number') {
windowHeight=window.innerHeight;
}
else {
if (document.documentElement&&
document.documentElement.clientHeight) {
windowHeight=
document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
return windowHeight;
}
window.onload = function(){
var t
t=getWindowHeight(this)
alert(t)
x=(t-400)
document.getElementById('row4r').style.padding-bottom=x+"px"
}

Just a note for the future, it is much easier to help if you format your code when posting.

genia
07-21-2008, 05:02 PM
first of all thanks for helping.here is the full page-and it's not working

http://www.stargatemedia.co.il/abou_tt%20(2).htm

god its furstrating.

jscheuer1
07-21-2008, 05:16 PM
This will never work:


document.getElementById('row4r').style.padding-bottom=x+"px"

It needs to be:


document.getElementById('row4r').style.paddingBottom=x+"px";

And, as mentioned already, document.getElementById('row4r') must already exist before this is executed, onload would be a good time because in IE, even the other dimensions you seek may not be available until that time anyway.

Another caveat, there must be only one element on the page with the row4r id.

genia
07-21-2008, 05:30 PM
man,thank you very very very very very very much

Dal
07-21-2008, 05:35 PM
Hehe well spotted jscheuer1

If they had there head screwed on when they named these DOM attributes they could have kept them the same for CSS and javascript then things like this would happed. :D

Dal

genia
07-21-2008, 06:15 PM
exactly.
tell me something..now the function getWindowHeight gives me the height of the browser?
can i change it to give me the height of the viewing port? how?


document.getElementById("row4r").style.height=document.screen.availHeight-660+"px"

not quiet working...
thanks again guys for your help

jscheuer1
07-21-2008, 07:37 PM
This generally works:


function set_row4r(){
var iecompattest = function(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
};

var wh = window.innerHeight? window.innerHeight : iecompattest().clientHeight;

document.getElementById("row4r").style.height = wh + 'px';
};
window.onload = set_row4r;

If you have other onload events, it would need to be integrated with them in one of the various ways available for that.

genia
07-21-2008, 08:26 PM
thank you very much
but i need to substruct from the result something like 610px -the total height of the existing elements above row4r

jscheuer1
07-21-2008, 11:56 PM
That would most easily be done in this line:


document.getElementById("row4r").style.height = wh + 'px';

like so:


document.getElementById("row4r").style.height = (wh - 610) + 'px';

However, you might not be sure of the exact figure in all cases. It could be arrived at by checking the the offsetHeight of those elements, adding them together and subtracting that result from wh in the parenthetical expression. If borders or margin exist and throw it off, they could be taken into account as well.

But I still think that this might be better worked out using layout and css (as I alluded to in another thread of yours on this topic). The solution I offered there (setting the body background color) would work in most browsers, but perhaps not in IE. I'm not sure why though. It could be due to the IE only stylesheet you are using, or might be a peculiarity of the IE browser. To determine which would require additional investigation.

At the very least we could use the body background color for most browsers and come up with an alternative for IE.

genia
07-22-2008, 07:12 AM
first of all thank you for your time and help.
secondly,i do use a background color but the thing is that i need 2 colors to fill the body.
i tried using background-color and putting an orange image and repeat it but it didnt worked.thats why i use JS.

and i know i will be much better if the script will calc the height of all the elements and then subtract the total from the user height.
i know how to this in theory but not how to code unfortunately.[loop trough the elements and use something like "for each" and add the value of the element height to the total and then doing the subtract form user res]