This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Define a JS object please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Define a JS object please help" Watch "Define a JS object please help" New topic
Author

Define a JS object please help

Nicholas Turner
Ranch Hand

Joined: May 24, 2003
Posts: 126
my main html file has
<html>
<head>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="c:\MainMenu.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="c:\menuItem.js"></SCRIPT>
<SCRIPT language="JavaScript1.2">
<!--
function loadMenus() {
window.spiritMenu = new MainMenu();
...
and the mainmenu.js file has
function MainMenu() {
this.description = "";
//if( parentMenu != null )
//this.parent = parentMenu;
this.toolTip = "";
var menuItems = new Array[0];

}
but it tells me that mainmenu is undefined. what am i doing wrong?
thanks,
nick
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

In

The URL is not valid, so the js file containing the object constructor is not being loaded. If you really want to use a file path to address the file (trust me, you don't), you need to use the file:// protocol format.
I'd highly advise that you move the js files to a web server-addressable location and use an http protocol to address the js file. This can be relative to the server, context or the current file.
hth,
bear
[ June 08, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nicholas Turner
Ranch Hand

Joined: May 24, 2003
Posts: 126
I understand, this is for testing(prototyping) only. Before I insert it to the web app area
Nicholas Turner
Ranch Hand

Joined: May 24, 2003
Posts: 126
thier located in the same directory. But I changed it and it still doesnt see it.
even when i just say SRC="mainMenu.js"
whats really wrong
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

I'd say that there's a 99% chance that the 'not defined' error is simply because the js file is not loading. To test this, you can place an alert in the JS file and see if it pops up when the page loads.
hth,
bear
Nicholas Turner
Ranch Hand

Joined: May 24, 2003
Posts: 126
your right
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Define a JS object please help
 
Similar Threads
javascript object how to retrieve properties
how to call js file from jsp
Passing workStation time to a servlet?
how to stop my return string from being encoded?
Calling JS from a folder.