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
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>

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

Yeh i know its a mess, its all dynamic generated from php loops and such.

 

Those validation errors are just the same one repeated 15 times.

 

I will look at it later, but its alot of work to go through and try to understand whats wrong

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

            <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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.