views:

21

answers:

1

Hi,

Thanks for your time,

I have calculated scrollHeight of <textarea> and run it on Microsoft Internet Explorer 8 and Firefox. I am getting different scrollHeight in above mentioned browsers.

Code used in my application

function getScrollHeight(id) {
     textareaObj = document.getElementById(id);
     var scrollH = textareaObj.scrollHeight;
     alert(scrollH);

}

Is scrollHeight of <textarea> in MSIE8 and FF differ ?

If so then how to achieve to get same scrollHeight in mentioned browsers?

Thanks,

-Pravin

A: 

In IE scrollHeight is calculated to the height of the content of the element, so if there is less content that no scrollbars are needed, you will get a value less than the height of the element.

In this case you can retrieve offsetHeight instead of scrollHeight.

If you need it very exact, you furthermore need to calculate with the padding and border-width of the element, it differs in both browsers what all they include to that. Also the font-size and line-height is related if you dont set them on your own, while every browser will take it's defaults.

Whatever you do, in IE access the propertys not before body's onload has fired, otherwise you will get weird results.

scrollHeight @ MSDN
scrollHeight @ MDC

Dr.Molle