views:

46

answers:

2

Hi, I was wondering if anybody knows how I would go about detecting when the scrollbar appears inside a text area. I am currently using mootools for my JavaScript but I am really having issues getting it to detect a scrollbar.

Any example would be useful thank you!.

Jamie

+6  A: 
function has_scrollbar(elem_id) 
  { 
   elem = document.getElementById(elem_id); 
   if (elem.clientHeight < elem.scrollHeight) 
    alert("The element has a vertical scrollbar!"); 
   else 
    alert("The element doesn't have a vertical scrollbar."); 
  } 
tommaso
Is this going to work for a textarea?
Pekka
Yes - http://jsfiddle.net/HBp5U/
Castrohenge
+1  A: 

Tommaso's solution works perfectly, even with a text area. But if the user were to type in the textarea and suddenly the textarea gave itself a scrollbar, your javascript wouldn't know or be triggered.So you might want to add something like

 onKeyUp='showDialog(has_scrollbar("textareaID"))'
Capt Otis