homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

External .js file doesn't display
Problem with quotation marks?

 6:32 am on Aug 25, 2002 (gmt 0)

I'm trying to make an external .js file for a list of links, but can't get it to display.

This works as expected:

<!-- Begin
document.write('TESTING TESTING');// End -->

But this doesn't display:

<!-- Begin
document.write('<P CLASS="menu"><A HREF="http://mysite.com/somefile.html">LinkText</A></P>');// End -->

My javascript experience is limited to customizing cut-and-paste scripts. My primitive troubleshooting leads me to suspect the problem has something to do with the quotation marks, but I don't know where to go from there.

Advice would be much appreciated.



 6:34 am on Aug 25, 2002 (gmt 0)

I would say take them out and try it, then you know. You don't really need them (except for validating). I don't know the escape char for js.


 7:31 am on Aug 25, 2002 (gmt 0)

I tried it with no quotation marks, and it still wouldn't work. For some reason I decided to try making the file in AppleWorks instead of SimpleText and it worked. I didn't (knowingly) change anything, just copied and pasted the code from one file into the other.

I now have a file that does what I want, but I'm not sure what made the difference. Scary stuff! ;)


 8:55 am on Aug 25, 2002 (gmt 0)

im pretty sure if you try single apostraphes instead of double quotes for the url you will be ok.

' instead of "

Escape character in js is \


 1:24 pm on Aug 25, 2002 (gmt 0)


document.write('<P CLASS="menu"><A HREF="http://mysite.com/somefile.html">LinkText</A></P>')

works OK for me. Your example is missing the ') from the end of the line. Not sure if that is missing in your real file, or was just a copy and paste problem.

Don't forget to call your file with a line like:

<SCRIPT type="text/javascript" language="javascript1.2" src="test.js"></SCRIPT>

Most people seem to forget the >> type="text/javascript" << part of this, which means that the document will fail to validate.


 2:11 pm on Aug 25, 2002 (gmt 0)

Failure to include the type attribute won't affect anything in any of the current browsers. (But if you're validating to XHTML, you might in addition want to write the HTML tags in lower case.)

If this is, as you say, an external file, it shouldn't cause any problems. As an internal file, you'll probably need to escape the <'s (use the JavaScript escape \074). You don't need to comment out the code, and if it's an external file you shouldn't comment it out.

You need to make sure you haven't done anything silly, like getting the src wrong in your <script> tag.

Above all, you need to give us more information. What browser are you seeing this on? Are you getting any error messages? If so, what are they?


 2:26 pm on Aug 25, 2002 (gmt 0)

There were no error messages; there was simply nothing, in either Netscape or IE (Mac). The first version (plain words) displayed properly, but when I inserted some HTML code instead, nothing happened. The only change was substituting the code bits for the test words; the surrounding content was left intact, and the call-the-file <script> line was not touched.

When I copied-and-pasted the entire file from SimpleText into AppleWorks and saved it with the same name, something changed so that things worked, but I don't know what it was. A mystery ...

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved