1. Home
  2. Computing & Technology
  3. JavaScript

Plain Text Please

By , About.com Guide

Every so often I get a request from someone to please look at the Javascript that they have copied to their site and tell them why it isn't working. The most common cause that I find when I investigate this for them is that their Javascript code is sprinkled throughout with a whole load of garbage characters that stop the code from working.

Well this code isn't exactly garbage, it is actually a whole series of formatting commands that their editor has placed there because they saved the file as a rich text document or word document or whatever format that they chose to save the file in. The problem is that they chose a format other than plain text to save the file in and so their editor has added these formatting commands to what it saved so that it can restore the formatting back the way it was when you view the file in that editor again.

Javascript doesn't like all of these formatting commands because it treats them as Javascript statements and tries to run them. This attempt is always unsuccessful and the end result is that the script doesn't run. Depending on which browser you are using and how you have it configured you may get error messages about the javascript. As this mistake is only made by beginners who have usually copied the script rather than writing it themselves the error messages don't normally mean very much to them.

So how can you tell if you have made this mistake and have stopped your javascript from running by saving it in the wrong format? Well opening the Javascript back up in the same editor wont help because that will just interpret the formatting that it put there the way that it expects. The best solution is to open the file in notepad (if you are using Windows) or a similar plain text editor (if you are using some other operating system). You will then easily be able to see the offending commands.

Better yet is to use a plain text editor such as notepad to create your Javascript files in the first place and so avoid the possibility of saving the files in the wrong format all together.

Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript
  4. Problem Solving
  5. Plain Text Please For JavaScript>

©2009 About.com, a part of The New York Times Company.

All rights reserved.