Link to home
Start Free TrialLog in
Avatar of VapiSoft
VapiSoft

asked on

JavaScript reset scrollWidth

Hi,
I have a table inside table's cells.
If the table has less than 10 lines then:  obj.scrollWidth =obj.offsetWidth
If the table has more than 10 lines then: it adds a vertical scrollbar, and: obj.scrollWidth < obj.offsetWidth
If after that I display a table that has less then 10 lines, it is not adjacent to the left but instead it leaves space as if there was a scrollbar there and I see the: obj.scrollWidth < obj.offsetWidth
How can I reset it back to normal (I tried: obj.scrollWidth=obj.offsetWidth;  but it doesn't work).
Avatar of HugoHiasl
HugoHiasl

Did you try to set the style "overflow:hidden" ?
In your case this would be:

obj.style.overflow = "hidden";


You can also try to set it to "auto" if you want it to decide itself if a scrollbar is needed or not.
Avatar of Gurvinder Pal Singh
you are adjusting scrollWidth and vertical scrollbars?
Not sure if i understood the requirement correctly (please correct me if i am wrong)

It appears that you want to set the specific length to height as well as width of the table cell.

In that case you can simply set the

td table
{
   width: 100px; //depending upon how much you want to show
   height: 100px; //depending upon how much you want to show
   overflow: hidden;
}

this will force all the tables inside the cells to be of specific height and width, and the overflowing text will be hidden.
Avatar of VapiSoft

ASKER

I cannot use obj.style.overflow='hidden' because it will not show more than 10 lines.
I want the table to show more then 10 lines with a scroll bar (if there are more then 10 lines),
but to show it with no scrollbar (as it does) when there are less then 10 lines, but it should be ajacent to the left (currently it leaves a space of abou 20 pixles).

I attach a picture, but please note that because I use dir="rtl" it is in the right instead of the left.
The Image.
ScreenShot-4432.jpg
ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I did
obj.style.overflowY='scroll';
and it solved the problem.
thanks for the points
Now I see that I made a mistake.
When there are less then 10 lines it adds a disabled scrollbar that looks very bad.
So I am back to square one, how to reset the scrollWidth?