Welcome to WebmasterWorld Guest from 54.226.133.245

Forum Moderators: open

Message Too Old, No Replies

External .js file doesn't display

Problem with quotation marks?

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

Moderator

WebmasterWorld Administrator buckworks is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2001
posts:5609
votes: 19


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)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 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)

Moderator

WebmasterWorld Administrator buckworks is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2001
posts:5609
votes: 19


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)

Senior Member

WebmasterWorld Senior Member chiyo is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:June 21, 2000
posts:3170
votes: 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)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0



Hmm,

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)

Preferred Member

10+ Year Member

joined:June 7, 2002
posts:475
votes: 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)

Moderator

WebmasterWorld Administrator buckworks is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2001
posts:5609
votes: 19


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 ...

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members