Jump to content

Firefox: Event undefined


idire

Recommended Posts

This code works in ie, but not in FF and I cant work out why...

 

JS

<script>
    /* this function shows the pop-up when
     user moves the mouse over the link */
    function Show(event)
    {
        /* get the mouse left position */
        x = event.clientX + document.body.scrollLeft;
        /* get the mouse top position  */
        y = event.clientY + document.body.scrollTop + 35;
        /* display the pop-up */
        Popup.style.display="block";
        /* set the pop-up's left */
        Popup.style.left = x;
        /* set the pop-up's top */
        Popup.style.top = y;
    }
    /* this function hides the pop-up when
     user moves the mouse out of the link */
    function Hide(event)
    {
        /* hide the pop-up */
        Popup.style.display="none";
    }
</script>

 

HTML

<a href="#" onMouseOut="Hide()" onMouseOver="Show()" 
  onMouseMove="Show()">Move the mouse over here</a><br>
  
  <div id="Popup" class="transparent">
    <div style="background-color: #003366">
      <b>Title goes here</b></div>
    <div></b>Description goes here</div>
</div>

 

CSS

  .transparent {
    filter:alpha(opacity=90);
    background-color:green;
    display:none;
    width:170;
    height:100;
    position:absolute;
    color: white;
    border: 1 green solid;
}

 

Firefox error console lists this as the problem line:

x = event.clientX + document.body.scrollLeft;

Link to comment
https://forums.phpfreaks.com/topic/121733-firefox-event-undefined/
Share on other sites

To access the event info, do it this way instead:

<style>
  .transparent {
    filter:alpha(opacity=90);
    background-color:green;
    display:none;
    width:170;
    height:100;
    position:absolute;
    color: white;
    border: 1 green solid;
}
</style>
<script>
    /* this function shows the pop-up when
     user moves the mouse over the link */
    function Show(event)
    {
        /* get the mouse left position */
        x = event.clientX + document.body.scrollLeft;
        /* get the mouse top position  */
        y = event.clientY + document.body.scrollTop + 35;
        /* display the pop-up */
        Popup.style.display="block";
        /* set the pop-up's left */
        Popup.style.left = x;
        /* set the pop-up's top */
        Popup.style.top = y;
    }
    /* this function hides the pop-up when
     user moves the mouse out of the link */
    function Hide(event)
    {
        /* hide the pop-up */
        Popup.style.display="none";
    }
    window.onload = function(){
      var ele = document.getElementById('test');
      ele.onmouseout = Hide;
      ele.onmouseover = Show; 
      ele.onmousemove = Show;
    } 
</script>
<a href="#" id="test">Move the mouse over here</a><br>
  
<div id="Popup" class="transparent">
  <div style="background-color: #003366">
    <b>Title goes here</b></div>
  <div>
  <div>Description goes here</div>
</div>

You added this?

 

window.onload = function(){
      var ele = document.getElementById('test');
      ele.onmouseout = Hide;
      ele.onmouseover = Show; 
      ele.onmousemove = Show;
    } 

 

Same error, event is undefined

 

also got the error: popup is undefined:

 

       

Popup.style.display="none";

oops...forgot to update that part. you can't just reference Popup, you need to use document.getElementById() to get it.

<style>
  .transparent {
    filter:alpha(opacity=90);
    background-color:green;
    display:none;
    width:170;
    height:100;
    position:absolute;
    color: white;
    border: 1 green solid;
}
</style>
<script>
    /* this function shows the pop-up when
     user moves the mouse over the link */
    function Show(event)
    {
      var Popup = document.getElementById('Popup');
        /* get the mouse left position */
        x = event.clientX + document.body.scrollLeft;
        /* get the mouse top position  */
        y = event.clientY + document.body.scrollTop + 35;
        /* display the pop-up */
        Popup.style.display="block";
        /* set the pop-up's left */
        Popup.style.left = x;
        /* set the pop-up's top */
        Popup.style.top = y;
    }
    /* this function hides the pop-up when
     user moves the mouse out of the link */
    function Hide(event)
    {
        /* hide the pop-up */
        document.getElementById('Popup').style.display="none";
    }
    window.onload = function(){
      var ele = document.getElementById('test');
      ele.onmouseout = Hide;
      ele.onmouseover = Show; 
      ele.onmousemove = Show;
    } 
</script>
<a href="#" id="test">Move the mouse over here</a><br>
  
<div id="Popup" class="transparent">
  <div style="background-color: #003366">
    <b>Title goes here</b></div>
  <div>
  <div>Description goes here</div>
</div>

Still says undefined for this line:

 

        x = event.clientX + document.body.scrollLeft;

 

 

EDIT: doesnt work on ie anymore:

 

Error: clientX is null or not an object

 

Code is from here btw

http://www.codeproject.com/KB/scripting/transparentpopup.aspx

 

 

ok...tested in FF and IE:

 

<style>
  .transparent {
    filter:alpha(opacity=90);
    background-color:green;
    display:none;
    width:170;
    height:100;
    position:absolute;
    color: white;
    border: 1 green solid;
}
</style>
<script>
    /* this function shows the pop-up when
     user moves the mouse over the link */
    function Show(e)
    {
        e = e ? e : event;
        var Popup = document.getElementById('Popup');
        /* get the mouse left position */
        x = e.clientX + document.body.scrollLeft;
        /* get the mouse top position  */
        y = e.clientY + document.body.scrollTop + 35;
        /* display the pop-up */
        Popup.style.display="block";
        /* set the pop-up's left */
        Popup.style.left = x;
        /* set the pop-up's top */
        Popup.style.top = y;
    }
    /* this function hides the pop-up when
     user moves the mouse out of the link */
    function Hide()
    {
        /* hide the pop-up */
        document.getElementById('Popup').style.display="none";
    }
    window.onload = function(){
        var ele = document.getElementById('test');
        ele.onmouseout = Hide;
        ele.onmouseover = Show; 
        ele.onmousemove = Show;
    } 
</script>
<a href="#" id="test">Move the mouse over here</a><br>
  
<div id="Popup" class="transparent">
  <div style="background-color: #003366">
    <b>Title goes here</b></div>
  <div>
  <div>Description goes here</div>
</div>

Added a </div> to the end of your code and it worked :)

 

Thanks for the help

 

 

 

 

EDIT: Why on firefox does the box appear on the far left, I wanted it to work like IE and appear where the mouse is, is that possible?

 

The error console comes up with:

 

error parsing value of property left/top declaration dropped

Without the </div> it puts my table following the code into the popup box

 

i'm using FF3 also

 

<style>
  .transparent {
    filter:alpha(opacity=90);
    background-color:#FFFACD;
    display:none;
    width:170px;
    height:100px;
    color: black;
    border: 2 green solid;
}
#popup { left:0; top:0; }

</style>
<script>
    /* this function shows the pop-up when
     user moves the mouse over the link */
    function Show(e)
    {
        e = e ? e : event;
        var Popup = document.getElementById('Popup');
        /* get the mouse left position */
        x = e.clientX + document.body.scrollLeft;
        /* get the mouse top position  */
        y = e.clientY + document.body.scrollTop + 35;
        /* display the pop-up */
        Popup.style.display="block";
        /* set the pop-up's left */
        Popup.style.left = x;
        /* set the pop-up's top */
        Popup.style.top = y;
    }
    /* this function hides the pop-up when
     user moves the mouse out of the link */
    function Hide()
    {
        /* hide the pop-up */
        document.getElementById('Popup').style.display="none";
    }
    window.onload = function(){
        var ele = document.getElementById('test');
        ele.onmouseout = Hide;
        ele.onmouseover = Show; 
        ele.onmousemove = Show;
    } 
</script>
<a href="#" id="test">Move the mouse over here</a><br>
  
<div id="Popup" class="transparent">
  <div style="background-color: #003366">
    <b>Title goes here</b></div>
  <div>
  <div>Description goes here</div>
</div></div>

 

capturefe9.png

 

ah...spotted the problem, there was an EXTRA </div> tag...change the HTML block to this:

<div id="Popup" class="transparent">
  <div style="background-color: #003366">
    <b>Title goes here</b>
  <div>
  <div>Description goes here</div>
</div>

the main ones that will give you issues are the missing end tags...i saw some in there for forms and spans

 

...something else....use this for your JS and let me know what the alerts are:

<script>
    /* this function shows the pop-up when
     user moves the mouse over the link */
    function Show(e)
    {
        e = e ? e : event;
        var Popup = document.getElementById('Popup');
        /* get the mouse left position */
        x = e.clientX + document.body.scrollLeft;
alert('x: '+x);
        /* get the mouse top position  */
        y = e.clientY + document.body.scrollTop + 35;
alert('y: '+y);
        /* display the pop-up */
        Popup.style.display="block";
        /* set the pop-up's left */
        Popup.style.left = x;
        /* set the pop-up's top */
        Popup.style.top = y;
    }
    /* this function hides the pop-up when
     user moves the mouse out of the link */
    function Hide()
    {
        /* hide the pop-up */
        document.getElementById('Popup').style.display="none";
    }
    window.onload = function(){
        var ele = document.getElementById('test');
        ele.onmouseout = Hide;
        ele.onmouseover = Show; 
        ele.onmousemove = Show;
    } 
</script>

hum, ok...it might not like that there isn't a px on the end....try this for your CSS and JS:

<style>
  .transparent {
    filter:alpha(opacity=90);
    background-color:#FFFACD;
    display:none;
    width:170px;
    height:100px;
    color: black;
    border: 2 green solid;
}
#popup { left:0px; top:0px; }

</style>
<script>
    /* this function shows the pop-up when
     user moves the mouse over the link */
    function Show(e)
    {
        e = e ? e : event;
        var Popup = document.getElementById('Popup');
        /* get the mouse left position */
        x = e.clientX + document.body.scrollLeft;
        /* get the mouse top position  */
        y = e.clientY + document.body.scrollTop + 35;
        /* display the pop-up */
        Popup.style.display="block";
        /* set the pop-up's left */
        Popup.style.left = x + 'px';
        /* set the pop-up's top */
        Popup.style.top = y + 'px';
    }
    /* this function hides the pop-up when
     user moves the mouse out of the link */
    function Hide()
    {
        /* hide the pop-up */
        document.getElementById('Popup').style.display="none";
    }
    window.onload = function(){
        var ele = document.getElementById('test');
        ele.onmouseout = Hide;
        ele.onmouseover = Show; 
        ele.onmousemove = Show;
    } 
</script>

            <div id="Popup<? echo $i; ?>" class="transparent">

            <div style="background-color: #90EE90">

            <b>Method Used:</b></div>

            <div>

            <div><? echo $user.$method; ?></div>

            </div></div>

 

how to I add the var $i to the hide/show?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.