Closed Bug 274085 Opened 20 years ago Closed 20 years ago

Firefox Javascript engine is not seeing global variables and some functions.

Categories

(Core :: JavaScript Engine, defect)

1.0 Branch
x86
Linux
defect
Not set
major

Tracking

()

RESOLVED DUPLICATE of bug 114461

People

(Reporter: philip, Unassigned)

Details

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; rv:1.7.3) Gecko/20041001 Firefox/0.10.1
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; rv:1.7.3) Gecko/20041001 Firefox/0.10.1

I've been doing some javascript programming in firefox. The version of firefox
I'm using is the prerelease to 1.0. 

I've needed to use some global variables to define some constants in an
externally defined Javascript file.  The browser for some unexplainable reason
is not seeing my variables and two of the functions are not seen either. 

I've pasted in the steps to produce the error my code example.  

Hopefully this will help you find the issue. In this example none of the global
variables are seen under the menuBuild function. Also the initialize function
doesn't see the open_menu or close_menu function.  I've tried this on both
firefox and netscape 7.1. So the problem seems to be with the Javascript engine
in general. 

Also I'm having trouble getting Javascript to make div fields disapear. However
I don't deny that this could be how I'm coding it. But Nothing I try seems to work. 

Reproducible: Always
Steps to Reproduce:
// Menu Item Type: DO NOT CHANGE THESE VALUES. 
// Field Type
var QUESTION = 1;
var ANSWER = 0;

// Path Field Index constants, DO NOT CHANGE THESE VALUES. 

// COMMON INDEXES; 
var MENU_ID_IDX = 0; 
var TYPE_FIELD_IDX = 1;

// Menu selection Only INDEXES 
var SELECTION_LABEL_IDX = 2; 
var NEXT_MENU_IDX = 3;
var TICKET_OUTPUT_IDX = 4;

// Menu Question Only INDEXES. 
var MENU_QUESTION_IDX = 2; 
var TICKET_QUESTION = 3; 


function open_menu(menuID) 
{

	var divID = document.getElementById(menuID);

}


function close_menu(menuID) 
{
	var divID = document.getElementByID(menuID); 

	divID.style.visibility = "hidden";
}


function initialize(menuList) 
{

	build_menu(menuList, 1);
	open_menu(1);
	
}



// function: buildMenu 
// Description: This function builds any given menu with a specific Menu ID 
// Input: Paths Array created by Create Paths
//        Menu ID 
//
// Output: HTML Code. 
// Created By: Philip Neves, philip@digitalinfiniity.biz
// Last Edited By: Philip Neves 
// Last Edited On: December 8 2004 
//

function build_menu(menus, menuID)
{
	// local variables. 
	var qstnCount = 0; 
	var chkMenuType; 


	document.write("<DIV ID='" + 
			menuID + 
		       " STYLE='visibility:hidden'>"); 
	document.write("<TABLE with='100%'>");
	for (var idx = 0; idx < menus.length; idx++) {
		if (menus[idx][MENU_ID_IDX] == menuID) {

			if ((menus[idx][TYPE_FIELD_IDX] == QUESTION) && !(qstnCount > 0)) {
				
				document.write("<TR><TD> " + 
						"<a onclick='close_menu(" + 
						menuID +
						")'>" + 
						menus[idx][MENU_QUESTION_IDX] +
						"</a></TD></TR>"); 
				
				qstnCount++; 

			}
			else if ((menus[idx][TYPE_FIELD_IDX] == QUESTION) && (qstnCount > 0)) {
				document.write("<TR><TD> ERROR: Too many questions" + 
						"for menuID= " + menuID + 
						"</TD></TR>" ); 
			}
			else {
				document.write("<TR><TD>" + 
					       "<a onclick='nextMenu(" + 
						menus[idx][NEXT_MENU_IDX] +
						")'>" +
						menus[idx][SELECTION_LABEL_IDX] +
						"</a>" +
					       "</TD></TR>"); 
			}
		}
		
 	} 
	document.write("</TABLE>");
	document.write("</DIV>");

}

Actual Results:  
The div fields do not cause the menu to disapear. And the Javascript program
won't run properly. The Javascript console is Is giving an error saying the
functions and variables are not defined when clearly they are in the same file. 

Expected Results:  
A menu that doesn't come up on the screen until we run the open_menu funciton.
Now the code for the open menu function isn't implemented yet because I can't
get the function to be seen at least by the Javascript engine.
This code is designed to create a dynamic menu from an array that is defined in
a seperate HTML file.  I didn't place the array in the program because that
aspect of the code appears to be working. 


Summary: Firefox Javascript engine is not seeing global variables and some functions. → Firefox Javascript engine is not seeing global variables and some functions.
you have a few problems with your js code, the most obvious one is
getElementByID in close_menu (should be getElementById). Could check your code,
fix all mistakes you find, then attach an HTML file (testcase) with the js code
inside that demonstrates the problem. thanks.
Component: General → JavaScript Engine
Product: Firefox → Core
Version: unspecified → 1.0 Branch
Well, could you please (1) attach an HTML page demonstrating your problem, and
(2) ask in webdev forums why your code isn't working, to make sure it is really
Firefox's bug and not your. Also please don't mail me directly, comment in the
bug instead. Or at least include the bug number in e-mail.
I actually found a solution to my problem. 

The problem stems from the use of classes as part of the style sheet. IE has the
same problem. Classes cause the div fields to do some wierd things. When I
removed  the classes and just set a seperate style for each div field I was able
to resolve the problem. 

I also changed from using the visibility tag to using the display tag. It seems
to work properly now. However... I'm wondering if the visibility tag doesn't
cause the fields to not be viewable on the screen then what does it do. Since
both IE and Firefox seem to have the same problem It seems to be a problem with
the CSS specification. The problem is resolved. 

I also found the solution to firefox not seeing my global variables. 

In my html file I had an the initialize function in the body tag tacked on with
an onload. The onload tag placed in the body html tag appearantly blows away all
html tags for the page and requires you to regenerate the web page. 

Thank you for your assistance. 
So do you still think there is a bug in Firefox here?
Assignee: firefox → general
QA Contact: firefox.general → pschwartau

*** This bug has been marked as a duplicate of 114461 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.