Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

'function not defined' error

843836Jun 6 2005 — edited Jun 6 2005
Hello guys !
I've got a problem on a JSP with some Javascript functions.

I have a function 'createMenu( )' which build my menu. For every menu items, the function creates a <div> tag and a <a> tag....
The 'href' attribute of the <a> tag is another javascript function ( the syntax is :
).

My problem is that the browser doesn't know the function 'show2ndLvl(i)'... and I really don't understand why... so when I click on one of the first level menu entry, I get the error "show2ndLvl is not define"...

If a call the "show2ndLvl" function in a normal <script> tag ( like is createMenu( ) ), it works perfectly well...

And if I save my file as an HTML file, it also works perfectly well ( unfortunately, I need it as a JSP... ).

Has anybody an idea how I can solve my problem ?

Here is a copy of my code :
<html><head>
<SCRIPT language="JavaScript">
var mnu1stLvl = [
	"Access Management",
	"General Information",
	"Payment Services",
	"Securities Services", 
	"CLS"
]
	
var mnu2ndLvl = [
	[ /* Access Management */
		'Change Password',
		'User management',
		'Administrate Subscriptions'
	], [ /* General Information */
		"test1", 
		"test2",
		"test3",
		"test4"
	], [ /* Payment Services */
	], [ /* Securities Services */
	], [ /* CLS */
	]		
]
	
function show2ndLvl( i ) {
	var str = "";
	for( j=0; j<mnu2ndLvl.length; j++ ) {
str = str + '<div id="mnu2ndLvl' + i + j + '">' + mnu2ndLvl[i][j] + '</div>';
}
document.getElementById('mnu2ndLvl' + i).innerHTML=str;
}

function createMenu( ) {
for( i=0; i<mnu1stLvl.length ; i++ ) {
document.write( '<div id="mnu1stLvl' + i + '"><a href="javascript:show2ndLvl(' + i + ')">' + mnu1stLvl[i] + '</div>' );
document.write( '<div id="mnu2ndLvl' + i + '"></div>' );
}
}

</SCRIPT>
</head>
<body><table><tr><td id="tdMnu">
<SCRIPT language="JavaScript">
createMenu( );
</SCRIPT>
</td></tr></table></body></html>


Many thanks in advance for any help !
Cheers and regards.
Eric</a>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2005
Added on Jun 6 2005
3 comments
264 views