Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Define a JS object please help

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Nicholas Turner
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand, this is for testing(prototyping) only. Before I insert it to the web app area
 
Nicholas Turner
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your right
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic