views:

726

answers:

4

I have a gridview and when i mouse hover on a particular column, i am loading an external div(position:absolute) into that position.This i have done by calling a js function in the onmouseover event of the gridview cell(gvTestGrid.cells[1].attributes.add("onmouseover","loadDIV();")). I am able to load the div properly on mouse hover, but the problem is my loaded div contains a dropdown and button inside it. when i try to move my mouse inside the div to click the button or select the dropdown list, the div moves away.This happens after i added onmouseout event(gvTestGrid.cells[1].attributes.add("onmouseout","removeDIV();"))

without onmouse out event my div will remain loaded there on the gridview cell.Please help

i have done a small sample

<html>
  <div id="divPopup" onmouseout="removeDIV(this,event);" style="display:none;width:100px;height:100px;color:Navy;border:2px;border-color:Red;border-style:solid;">
    Yes its me
    </div>

    <table>
    <tr><td>A</td></tr>
    <tr><td>S</td></tr>
    <tr><td onmouseover="loadDIV(event)" onmouseout="removeDIV(this,event);">D</td></tr>
    <tr><td>E</td></tr>
    </table>

</html>
<script language="javascript" type="text/javascript">
function loadDIV(evt)
{
var myWin = document.getElementById('divPopup');
myWin.style.position='absolute';
myWin.style.left = evt.x;
myWin.style.top = evt.y;
myWin.style.display='block';

}

function removeDIV(obj,evt)
{
var myWin = document.getElementById('divPopup');
myWin.style.display='none';
myWin.style.left = 0;
myWin.style.top = 0;
}
</script>

if you try to enter mouse into the div it will move away.Any solution for this please??

+1  A: 

How about removing the div after you are done with the work in the DIV you have popped up? So you would close the DIV when you click the button in the DIV (Assuming it does work and should close afterward) or in a similar manner.

The Sheek Geek
A: 

It seems like the onmouseout event should be attached to the div.

Kevin Crowell
i tried that too..it works the same way
+1  A: 

Set a small timeout for hiding the div and clear this timeout in the onmouseover handler for the div.

vit
A: 

If you don't have Anchor tags in this content, may I suggest some CSS magic?

CSS here

a.MyCellPopup div.MyPopup {display:none;}
a.MycellPopup {position:relative;} /* Make pop up's position relative to the anchor tag */
a:hover.MyCellPopup div.MyPopup {display:block;position:absolute;top:10px;left:10px}

HTML Here

<a href="#" onclick="return false;" class="MyCellPopup">
    <div class="MyPopup">POP UP STUFF without links (links won't work)</div>
</a>

I have an onclick="return false" so if they click on the cell, they won't be brought to the top of the page. The href needs to be in there or else IE won't recognize the hover. I got this idea from ZenGarden for how to do simple pop ups.

If this still doesn't work I highly recommend visiting the YUI library, they have a javascript widget for exactly this problem.

Zoidberg