![]() |
| Javascript Tips |
|
<script language="Javascript" type="text/javascript">
var d = new Date(document.lastModified)
document.write("Last modified on " + d)
</script>
|
|
|
Don't forget that Javascript variables are case sensitive so that MyVar is not the same as myvar. Ensure that function names are spelled correctly and do not have any spaces or extraneous characters. Ensure that all function names in a script are unique. Except for the 'For' statement all argument lists are separated by commas. Check that the {} characters use to identify a statement block are placed correctly. All strings should have quotes around them, also ensure that the same quotation marks are used on the string, either (') or ("). Names of objects must be spelled with the correct capitalisation, i.e. Date, Array, Object etc. Use the double equals signs (==) in a comparison expression. |
|
|
'function does not always return a value' - The return statements in your function don't always return a value, ensure that they all either return a value or not. 'identifier is a reserved word' - The variable is a reserved word in Javascript. 'missing (...' or 'missing )...' - Either the open or close brackets is missing from a statement. 'missing ; after for-loop condition' or 'missing ; after for-loop initialise' - The 'for' statement is missing one of it's semicolons. 'missing { before function body' or 'missing } after function body' or 'missing } in compound statement' - Missing brace for a function or statement. 'nested comment' - You can't nest comments in Javascript. 'syntax error' - An error that Javascript has detected but unable to determine it's exact nature. 'unterminated string literal' - Missing " or ' at the end of a string literal. '... cannot be indexed as an array' - Trying to use a non object as an array. '... has no properties' - Attempting to reference properties of an object that has no properties. '... is not defined' - Referencing a variable that does not exist. |
|
<script language="Javascript" type="text/javascript"> document.myform.myinput.focus() </script> <form id="myform" name="myform" action=...> <input type="text" id="myinput" name="myinput"...> </form> |
|
|
onAbort - occurs with the browser STOP button is selected onClick - occurs when the object is clicked onFocus - occurs when the object receives focus onBlur - occurs when the object looses focus onMouseOver - occurs when the mouse passes over the object onMouseOut - occurs when the mouse leaves the object onSubmit - occurs when a forms Submit button is selected onChange - occurs when the text field contents change onSelect - occurs when the text field contents are selected onReset - occurs when a forms Reset button is selected onLoad - occurs when a image or document is loaded onUnload - occurs when a image or document is unloaded |
|
// Where supported in NN: (>NN4.0) var winWidth = window.innerWidth; var winHeight = window.innerHeight; // Where supported in IE: (>IE4.0) var winWidth = document.body.clientWidth; var winHeight = document.body.clientHeight; |