FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


What wrong with this js file ? Need help .





Summer
Code:
//   Navigation menu in every page

document.write('<span class="genmed" style="line-height:150%">');

document.write('<a href="index.html">Index</a><br />');

document.write('<a href="forum.html">Forum</a><br />');

document.write('<a href="download.html">Download</a><br />');

document.write('<a href="members.html">Members</a><br />');

document.write('<a href="help.html">Help</a><br />');

document.write('</span>');


I saved this as nav.js and I wrote this in index.html :

Code:
<script type="text/javascript" src="nav.js"></script>


I don't know whats the problem , please help me . thanks .
djcaution
Firstly you're probably already doing this but just in case....

make sure you have a <SCRIPT LANGUAGE="javascript"> at the start and ending it with </SCRIPT>

Now moving on to what I think the problem is.. you're using double-quotes inside your single quotes. It's supposed to be the other way around. For example:

document.write('<a href="index.html">Index</a><br />');
should be
document.write("<a href='index.html'>Index</a><br />");

but I really dont know what I'm talking about with js i just looked that up form a tutorial site just now to try and solve the riddle for fun. Lemme know if I'm right! Smile
JustaMin
djcaution wrote:

document.write('<a href="index.html">Index</a><br />');
should be
document.write("<a href='index.html'>Index</a><br />");


Shouldnt make a difference. I cant see any problem with the code but then i dont know alot about JS. Quotes shouldn't matter though as long as you are consistant.

Why dont you just use PHP to do this, it'd be much easier?
Chris Tiaens
The problem are indeed the double-qoutes inside the single qoutes, but I don't think changing it the the other way around would solve the problem in all browsers.
Better is to type a backslash before each qoute that has to be interpreted as text, like this:
Code:
//   Navigation menu in every page

document.write('<span class=\"genmed\" style=\"line-height:150%\">');

document.write('<a href=\"index.html\">Index</a><br />');

document.write('<a href=\"forum.html\">Forum</a><br />');

document.write('<a href=\"download.html\">Download</a><br />');

document.write('<a href=\"members.html\">Members</a><br />');

document.write('<a href=\"help.html\">Help</a><br />');

document.write('</span>');


I just hope you are planning to give it a better lay-out?? Smile Razz
dandelion
Well, the first thing I would like to say is that your script works properly for me - or almoust properly. Smile

Perhaps you should remove the <br /> tags if you want to get a horizontal menu, otherwise replace the inline <span> container with the block <p> or <div> one.

If you have no output at all, check whether (1) the index.html and nav.js files is in the same directory and (2) the nav.js filename is exactly in lower case.

Don't worry about double quotes inside of single ones because it is in common use for javascript outputting HTML code. It seems quite comfortable due to you can still use double quotes with attributes of HTML elements.

Please note the ' language="JavaScript" ' attribute is deprecated in modern (X)HTML standards. The ' type="text/javascript" ' is enough.
Summer
Okay , I will try it out first . Please check back soon , maybe I need help again .
Summer
lol , I tried what u all say and it remains the same . I can't figure what happened too ... Maybe I use too much javascript in the same page ? I used about 4 ...
Summer
lol , u know what happened ? I created the js file by :

Right Click > New > RTF Document

And that's the problem !! Solved now !
Related topics
How to create links in one .js file?
A search to make JS file even smaller-2306byte to 542
Editing a .js file...
I need web/flash/js help
Javascript Gallery Help (get some FRIH$)
Master Tutorial on SEO
HELP with Javascript!
PHP Read File Help needed.
Ajax or JS - need help ASAP
Off-Screen Objects Javascript
Help me with MySQL Account Maintenance and phpBB 2.0.15 :((
Tutorial: Image Rollovers w/ Javascript
Mambo simplifications needed
JavaScript (Menu)
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.