tags:

views:

64

answers:

3

I don't know much about this, just having recently started with JavaScript, so simple language would be greatly appreciated.

Whenever I insert JavaScript on a page, it appears in the preview as text on the page and when I update my site it also appears this way. How would I fix this?

Thank you in advance.

+2  A: 

Do you have it within <script type="text/javascript"></script> tags?

RememberME
Thank you. I feel a little foolish, but I suspect that I might inadvertently have left that out.
Chris
A: 

You need to provide a sample of what you are doing for us to help you.

However, you might check that your script declaration looks something like this:

<script type="text/javascript">
<!-- //html comment hides script from really old browsers

  myVar = resultsFromAMethod();

//-->
</script>
Timothy Lee Russell
I think it turned out that I hadn't put in the <script type= and </script>, which shows me up pretty clearly as being a real novice. I kind of came across a solution by chance while pasting this line of code for lightbox: <script type="text/javascript" src="lightbox.js"></script>But you make a very good point -- I'll make sure I paste in the code next time so you don't have to guess. Thank you.
Chris
+1  A: 

There are two ways to inject JavaScript into a page.

Inline in either the head or body of your html page.

<script type="text/javascript">
    alert('this is inline javascript');
</script>

Or you can link to an external JavaScript file from the head of your html document.

<script type="text/javascript" src="path/to/script.js"></script>

Just remember: if the javascript is an external file, save it with the .js extension.

Moses
Thanks. This is all very useful. It also makes me realize how much I have to learn. Foo instance, I don't even have a good grasp of how you comment something out in javascript. Is there a really good, easily understandable manual online somewhere? I'm gradually learning flash and I'm trying to make a series of overlays for flash-based audio players.
Chris
I would recommend starting off by watching Youtube videos on JavaScript (TheNewBoston has the best series), then I would pick up a book (JavaScript: The Definitive Guide does the best job of explaining advanced concepts).
Moses