Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2009, 01:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Question JS function not seen

Hi All,
I have a typical JS rollover menu that is giving me a Object Expected error.
I am not able to tell what the issue is.
I have simplified things a little to test the code.
So on the mouseover i now call a blanc test function with no parameters and the error still occurs.
I'm really not sure how to debug this any further?
The blow snippet is includes the test function and onmouseover="test();"

The error occuring on the call to the test() function.
I would really appreciate any advise.
Best Regards,
Rod
Code:

function test()
{
alert('boo');
}
</script>
<divstyle="width: 760px; padding: 0px30px0px16px;">
<tablecellpadding="7"cellspacing="7"style="margin-top: -20px;padding-top:10px; padding-right:30px;"align="center"border="0">
<tr>
<td>
<ahref="#"><spanonmouseover="test();onMouseOverMenu(this);"onmouseout="onMouseMenuOut(this);"class="mnuItemNormal">Gallery</span></a>
</td>
Full Menu Code
Code:
<script language="javascript" type="text/javascript">
    function onMouseOverMenu(obj)
    {
        obj.className = 'mnuItemOver';
    }
    
    function onMouseMenuOut(obj)
          
        obj.className = 'mnuItemNormal';        
    }
    function test()
    {
    alert('boo');
    }
</script>     
<div style="width: 760px; padding: 0px 30px 0px 16px;">
    <table cellpadding="7" cellspacing="7" style="margin-top: -20px;padding-top:10px; padding-right:30px;" align="center" border="0" >
        <tr>
            <td>
                <a href="#" ><span onmouseover="test();onMouseOverMenu(this);" onmouseout="onMouseMenuOut(this);" class="mnuItemNormal">Gallery</span></a>
            </td>
            <td>
                <a href="Create.aspx" id="LightWindowLink" class="lightwindow" params="lightwindow_type=external,lightwindow_width=880,lightwindow_height=656"  title="" author="" caption="" >
                     <span class="mnuItemNormal" onmouseover="onMouseOverMenu(this);" onmouseout="onMouseMenuOut(this);">Create one</span></a>
            </td>
            <td class="mnuItemNormal">
                <a href="http://jaal.allaboutlife.com.au/Jesus_has_Answer.aspx" class="mnuItemNormal" target="_parent">
                    <span onmouseover="onMouseOverMenu(this);" onmouseout="onMouseMenuOut(this);"  class="mnuItemNormal"> View TV ad</span></a>
            </td>
            <td class="mnuItemNormal">
                <a href="http://jaal.allaboutlife.com.au/whoisjesus.aspx" class="mnuItemNormal" target="_parent">
                    <span class="mnuItemNormal" onmouseover="onMouseOverMenu(this);" onmouseout="onMouseMenuOut(this);">Who is Jesus</span></a>
            </td>
            <td class="mnuItemNormal">
                <a href="http://jaal.allaboutlife.com.au/Orde...pelofMark.aspx"
                    target="_parent">
                    <span class="mnuItemNormal" onmouseover="onMouseOverMenu(this);" onmouseout="onMouseMenuOut(this);">Gospel Mark</span></a>
            </td>
            <td class="mnuItemNormal">
                <a href="http://jaal.allaboutlife.com.au/whats_on.aspx" target="_parent" >
                    <span onmouseover="onMouseOverMenu(this);" onmouseout="onMouseMenuOut(this);" class="mnuItemNormal">What's On</span></a>
            </td>
            
        </tr>
    </table>
</div>
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old October 23rd, 2009, 01:37 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

One very minor change and it worked for me:
Code:
    function onMouseMenuOut(obj)
    { /* YOU WERE MISSING THE LEFT BRACE HERE */          
        obj.className = 'mnuItemNormal';        
    }
You know, any decent debugger--or even the stupid ones MS has--would have found that immediately.

I recommend that you start using FireFox with the Firebug plugin. You would have found that in about 5 seconds.
 
Old October 23rd, 2009, 01:39 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Oh, and the "object" that was giving the "object expected" error was indeed that function.

Functions *are* objects in JS, so when the function didn't compile, it didn't exist. Ergo, every time you referenced it..."object expected".
 
Old October 23rd, 2009, 01:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Thumbs up

Thanks very much for that.
I had tried that, but in conjunction with other changes, best to start from the beginning I guess.
I didn't write the code and thought I had introduced the missing bracket in my changes.
Many thanks you saved me a heap.
Regards,
Rod
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling JS Function from VS? Ron Howerton Javascript 15 September 17th, 2008 02:35 PM
how to run a .js file from a javascript function sbkumar Javascript How-To 1 July 11th, 2008 11:12 AM
passing empty parameters to a js function crmpicco Javascript How-To 0 September 20th, 2005 10:16 AM
function in linked js file 'is not defined' John K. King Javascript 4 May 7th, 2004 09:04 PM
Trigger a JS function on loss of focus apd8x Javascript 1 July 14th, 2003 09:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.