Connecting Tech Pros Worldwide Forums | Help | Site Map

offsetHeight and offsetWidth not working in IE and Mozilla both

dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#1: Mar 3 '09
HTML code

Expand|Select|Wrap|Line Numbers
  1. <div id="dtls_DIV" style="background-color:#CCCCCC;border-style:solid;border-width:1px;border-color:#000000;display:none;position:absolute;height:180px;width:230px;overflow:auto">
  2.     <table id="dtls_TAB" border=0 cellpadding="2" cellspacing="2" width=100%>
  3.         <tr>
  4.             <td nowrap id="dtls_TD" class="searchbgcolor" style="background-color:#DDEEEE">Not Available<BR/></td>
  5.             <td align="right" valign="top"><input type=button class=button value="X" onclick="document.getElementById('dtls_DIV').style.display='none';" title="close the window"/></td>
  6.         </tr>
  7.     </table>
  8. </div>
  9.  
Javascript Code
Expand|Select|Wrap|Line Numbers
  1. function showList(value,obj){
  2.     alert(value);
  3.     var pos = findPos(obj);
  4.     var left = pos[0], top = pos[1];
  5.     var div_ref = document.getElementById('dtls_DIV');
  6.     if(value!='') document.getElementById('dtls_TD').innerHTML = value;
  7.     else document.getElementById('dtls_TD').innerHTML = 'Not Available</BR>';
  8.     div_ref.style.left = left+'px';
  9.     div_ref.style.top = top+'px';
  10.     var dtls_TAB = document.getElementById('dtls_TAB');
  11.     div_ref.style.height = (dtls_TAB.offsetHeight+10)+'px';
  12.     div_ref.style.width = (dtls_TAB.offsetWidth+10)+'px';
  13.     div_ref.style.display = 'block';
  14. }
  15.  
On first click(method call) it's not working on 2nd click(method call) it's working.
Why it's happening .....

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,652
#2: Mar 3 '09

re: offsetHeight and offsetWidth not working in IE and Mozilla both


how are these two codes related? the Javascript is not triggered as far as I see.
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#3: Mar 3 '09

re: offsetHeight and offsetWidth not working in IE and Mozilla both


When onClick event fires from any element then it happens.
Actually i thought no matter from where the method called, that's why i didn't post the calling of method ;)

Actually what's happening ... offsetHeight and offsetWidth returns zero... :(
Needs Regular Fix
 
Join Date: Jun 2006
Posts: 424
#4: Mar 4 '09

re: offsetHeight and offsetWidth not working in IE and Mozilla both


It looks like you are trying to get the offset size of an element whose style.display is 'none'.

offsets are figured from the rendered size of an element- the space it takes up in the browser window. If the display is none, it has no offset size, or 0.
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#5: Mar 4 '09

re: offsetHeight and offsetWidth not working in IE and Mozilla both


Ah..aah...I see ..Thanks for your reply ;)
Reply