JavaScript Problem!

He has: 153 posts

Joined: Nov 2004

Hi, I'm having some problems that are really killing me. I've been trying to fix this for over 7 hours now and I have tried EVERYTHING that I can think of. I need more brain power Sticking out tongue. Perhaps I can borrow some of yours.

Heres the problem. I'm trying to call some js into my html document so that i can easily change links around sitewide with one edit. The thing is i really need to send a couple of files for you to understand the problem. I'll cut and paste everything here I suppose..

Here is my main index file:

Quote: <script src="js/cts.jsp" langauge="javascript"></script>
<script src="js/navigation.jsp" langauge="javascript"></script>

website designer tennessee - Memphis web page design, hosting, marketing and promotion

<script language="javascript">navigation()</script>

about - memphis webpage designer

where the js function 'navigation' is from this jsp file:

Quote: function navigation()
{
tennessee designerdesigner memphiswebsite'
}

thats all one massive line..

and then the other js on the page works fine.

The problem is that i dont see my navigation in any broswer, its just not there! help pleeease!

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

It appears the main problem is you have HTML inside your function. You need JAVASCRIPT inside your function, not HTML.

To output the HTML from javascript function, you will have to use a something like document.write("{html}"); function. Not also you will have to escape all quotes (change your current "'s to \"'s.

Try something like:

function navigation()
{
document.write(\"<table width=\"778\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"89\"><a href=\"../index.html\"><img src=\"../images/3_02.gif\" alt=\"tennessee designer\" width=89 height=28 border=\"0\"></a></td><td width=\"85\"><img src=\"../images/3_03.gif\" width=85 height=28 alt=\"designer memphis\"></td><td width=\"195\"><img src=\"../images/3_04.jpg\" width=195 height=28 alt=\"website\"></td><td width=\"59\"><a href=\"../index.html\" onMouseOver=\"MM_swapImage('Image6','','../images/Home.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"../images/3_05.gif\" alt=\"\" name=\"Image6\" width=59 height=28 border=\"0\" id=\"Image6\"></a></td><td width=\"81\"><a href=\"../aboutus/aboutus.html\" onMouseOver=\"MM_swapImage('Image7','','../images/About-Us.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"../images/3_06.gif\" alt=\"\" name=\"Image7\" width=81 height=28 border=\"0\" id=\"Image7\"></a></td><td width=\"80\"><a href=\"../Services/Services.html\" onMouseOver=\"MM_swapImage('Image8','','../images/Services.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"../images/3_07.gif\" alt=\"\" name=\"Image8\" width=80 height=28 border=\"0\" id=\"Image8\"></a></td><td width=\"80\"><a href=\"../contactus/contactus.html\" onMouseOver=\"MM_swapImage('Image9','','../images/Contact-Us-top.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"../images/3_08.gif\" alt=\"\" name=\"Image9\" width=80 height=28 border=\"0\" id=\"Image9\"></a></td><td width=\"109\"><a href=\"../Testimonials/Testimonials.html\" onMouseOver=\"MM_swapImage('Image10','','../images/Testimonials.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"../images/3_09.gif\" alt=\"\" name=\"Image10\" width=109 height=28 border=\"0\" id=\"Image10\"></a></td></tr></table>\");
}
'

(Note if you break this up to be several lines instead of one long line, I think javascript doesn't like to continue down to the next line. (I could be wrong). If so, for each line you will have to wrap it with the document.write(" ");.

I hope that on your page you are providing an alternative method of naviagation, as some people browse with javascript disabled, so they would not get any of this.

A better alternative if you have access to it, is use PHP another server side scripting to include a file with your navigation menu. Although the plus side with javascript is that all the menu system is cached when they visit your site the first time, so it doesn't have to download each additional page they go to.

-Greg

He has: 153 posts

Joined: Nov 2004

I'm retarded and cut and paste from the wrong thing, but I did fix my problem. I was using document.write('html'); but i was trying to call a function from javascript that didnt exist! Thanks greg Smiling

You are right about the lines btw, it all has to stay one line, there are ways around it but they are shifty at best. Your also right about PHP which yes i have access to it. But i liked the javascript benifits Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.