Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 5 of 7
<SCRIPT>
document.write ("Hello<P>");
document.test.box.value = "Hello again";
</SCRIPT>
<FORM NAME="test">
<INPUT TYPE="text" NAME="box">
</FORM>
A common problem is referring to a form as a property of a window. This results in a confusing error -- "formname has no properties" (formname is the name of the form). It's confusing because the form is obviously an object with properties. For example, the following JavaScript says "test has no properties," yet it's obvious the test form is a valid object with properties:
<FORM NAME="test">
<INPUT TYPE="text" NAME="box">
</FORM>
<SCRIPT>
window.test.box.value = "Hello";
</SCRIPT>
The fix is to reference the form as a document property, as in:
document.test.box.value = "Hello";
Some of JavaScript's objects return values that look like strings, but they are not true strings. For instance, the following
displays the name of the current document URL. Although the return value looks like a string, it is not, and therefore doesn't
support any string object methods or properties, such as indexOf or toUpperCase.
var ret = location;
alert (ret.toUpperCase()); // results in an error
You need to convert the return value to a true string, then use the string methods/properties with the converted value. The
toString method offers one general approach you can often use:
var ret = location.toString();
alert (ret.toUpperCase()); // no error this time
Here is a list of the more common error messages you are likely to encounter when working with JavaScript. The messages are listed in alphabetical order in two sections: load-time errors (errors that occur when a script is loaded into the browser) and runtime errors (errors that occur when you play a script).
These error messages appear when an HTML document containing JavaScript is first loaded.
JavaScript found one or more return statements in a function that returned a value, and at least one return statement that didn't return anything. For example, the following script will result in an error in JavaScript:
function myBadFunction (val) {
if (val==0)
return;
else
return ("some text")
}
To fix this error, make sure all of the return statements are the same. All should return either something or nothing.
You tried to name a variable or object with a word that is reserved by JavaScript. Some words are reserved because they are
used by JavaScript as names for statements, functions, methods, or objects. Other words are reserved for future use. These
words are not currently used by JavaScript, but may be used some day. For example, the word int is reserved for future use. Using int as the name of a variable results in the "identifier is a reserved word" error:
int = "this is a test";
These errors (the ... denotes additional error message text) occur when you've forgotten to add the appropriate opening or closing parenthesis in your JavaScript code. For example, the error "missing ) after for-loop control" occurs with the following: