Jump to content

Function is not defined ? Please help


wizi

Recommended Posts

Hi everyone, I am new to Javascript. Please help me with this. Here is the code.

<head><script type="text/javascript" >function createtoplinks(){					document.write ("<ul class='site-nav'>");			  document.write("<li class='m1'>");						  			  document.write("<a  href='compareDNA.html'><img src='images/m1.png' alt='Sequences Analysis'/></a>");						  			  document.write("</li>");			  			  document.write("<li class='m2'>");						  			  document.write("<a  href='news.html'><img src='images/m2.png' alt='New & Events'/></a>");						  			  document.write("</li>");			  			  document.write("<li class='m3'>");						  			  document.write("<a  href='calendar.html'><img src='images/m3.png' alt='Calendar'/></a>");						  			  document.write("</li>");						document.write("<li class='m4'>");						  			  document.write("<a  href='aboutus.html'><img src='images/m4.png' alt='About Us'/></a>");						  			  document.write("</li>");			document.write("<li class='m5'>");						  			  document.write("<a  href='contactus.html'><img src='images/m5.png' alt='Contact Us'/></a>");						  			  document.write("</li>");		document.write ("</ul>");	return.true;}</head><html>.............<script type="text/javascript">		//This script create top links from XML file			createtoplinks();	</script>...........</html>

Simple right? Its just a simple code to help me create the links on the top of my page but i always get the error createtoplinks() is not defined? Please help.

Link to comment
Share on other sites

Some browsers will make the adjustment if elements are not where they belong, especially if the DTD is not strict. You should still make the correction Ingolme points out.But I suspect a bigger problem is this:

return.true;

You have typed a dot where you need a space. One syntax error in a function will keep the function from being defined. Your Firefox Error Console will point out errors like that as soon as you load the page. Use it whenever you are developing.In this case you don't even need a return value, and certainly not a Boolean value, since you don't use a return value where you call the function. You could easily delete the whole statement.

Link to comment
Share on other sites

also, I don't think it's safe practice to base your navigation on something that users can turn on or off.

Link to comment
Share on other sites

Certainly a better option would be to create the links in PHP or ASP, etc. OP might want to think about learning one of these.I suppose it's also possible that the page will look and behave in a satisfactory manner without the nav links created by the current routine. I don't know.

Link to comment
Share on other sites

you didn't close out your script..

<html><head><script type="text/javascript" >function createtoplinks(){					document.write ("<ul class='site-nav'>");			  document.write("<li class='m1'>");						  			  document.write("<a  href='compareDNA.html'><img src='images/m1.png' alt='Sequences Analysis'/></a>");						  			  document.write("</li>");			  			  document.write("<li class='m2'>");						  			  document.write("<a  href='news.html'><img src='images/m2.png' alt='New & Events'/></a>");						  			  document.write("</li>");			  			  document.write("<li class='m3'>");						  			  document.write("<a  href='calendar.html'><img src='images/m3.png' alt='Calendar'/></a>");						  			  document.write("</li>");						document.write("<li class='m4'>");						  			  document.write("<a  href='aboutus.html'><img src='images/m4.png' alt='About Us'/></a>");						  			  document.write("</li>");			document.write("<li class='m5'>");						  			  document.write("<a  href='contactus.html'><img src='images/m5.png' alt='Contact Us'/></a>");						  			  document.write("</li>");		document.write ("</ul>");	return.true;}</script></head>.............<script type="text/javascript">		//This script create top links from XML file			createtoplinks();	</script>...........</html>

Link to comment
Share on other sites

Thanks everyone for the suggestion. I tried all the suggestions but it still doesnt work on Firefox and Chrome. However, It DOES work on IE8 after I allow the script to run. I guess this is the matter of security just like Deirdre's Dad said. Is there anyway that you can create the links without using ASP or PHP?

Link to comment
Share on other sites

Thanks everyone for the suggestion. I tried all the suggestions but it still doesnt work on Firefox and Chrome. However, It DOES work on IE8 after I allow the script to run. I guess this is the matter of security just like Deirdre's Dad said. Is there anyway that you can create the links without using ASP or PHP?
whats wrong with HTML/CSS?can you post the changes you've made? Are you checking for errors in the console like DD suggested?edit: just noticed you said this was coming from an XML file...is that code supposed to be in the script? I don't see it. Or has that not been implemented yet?
Link to comment
Share on other sites

Sorry for the confusion. When i post the code here, I changed it a little bit. I tried to use XML at first but I also got the error "is not defined. So I took the XML part out but I forgot to delete this line "//This script create top links from XML file." There is no XML here. I changed the code to what lu13cky suggested. Thats all. It works on IE8 (after I allow the script to run), NOT working with Firefox or Chrome.

Link to comment
Share on other sites

I changed the code to what lu13cky suggested. Thats all. It works on IE8 (after I allow the script to run), NOT working with Firefox or Chrome.
lu13cky didn't make the change that DD pointed out. So if you have exactly what lu13cky posted you still have this error:
But I suspect a bigger problem is this:
return.true;

You have typed a dot where you need a space. One syntax error in a function will keep the function from being defined. Your Firefox Error Console will point out errors like that as soon as you load the page. Use it whenever you are developing.In this case you don't even need a return value, and certainly not a Boolean value, since you don't use a return value where you call the function. You could easily delete the whole statement.

Link to comment
Share on other sites

so, as I was saying...

can you post the changes you've made? Are you checking for errors in the console like DD suggested?
Link to comment
Share on other sites

try this, but! i agree that using javascript to fully reproduce a menu list is not not the best way to go.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><script type="text/javascript">/*<![CDATA[*//*---->*/function createtoplinks(){ document.write ("<div style='width:960px; margin: 0 auto;'>"); document.write ("<ul class='site-nav'>"); document.write("<li class='m1'>"); document.write("<a href='compareDNA.html'><img src='images/m1.png' alt='Sequences Analysis' /></a>"); document.write("</li>"); document.write("<li class='m2'>"); document.write("<a href='news.html'><img src='images/m2.png' alt='New & Events' /></a>"); document.write("</li>"); document.write("<li class='m3'>"); document.write("<a href='calendar.html'><img src='images/m3.png' alt='Calendar' /></a>"); document.write("</li>"); document.write("<li class='m4'>"); document.write("<a href='aboutus.html'><img src='images/m4.png' alt='About Us' /></a>"); document.write("</li>"); document.write("<li class='m5'>"); document.write("<a href='contactus.html'><img src='images/m5.png' alt='Contact Us' /></a>"); document.write("</li>"); document.write ("</ul>"); document.write ("</div>"); //return.true;}/*--*//*]]>*/</script> <style type="text/css">ul.site-nav{list-style:none;}ul.site-nav li{float:left; background-color:#CC66FF; height:30px;}ul.site-nav li a{float:left; padding:0 15px; background-color:#FFCC66; display:block; height:30px;line-height:30px; width:auto;}ul.site-nav li a img{border:none;}</style></head><body><div style="width:960px; margin:0 auto; "><script type="text/javascript">/*<![CDATA[*//*---->*/ //This script create top links from XML file createtoplinks(); /*--*//*]]>*/</script> <div style="clear:both;"><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex.</p> </div></div></body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...