This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Javascript is a programming languageJavascript is a programming language It is a It is a simplesimple, , object-based object-based interpretedinterpreted scripting scripting
languagelanguage Code is usually embedded in the HTMLCode is usually embedded in the HTML Javascript is Javascript is NOTNOT Java Java Javascript is not Jscript or Active-X, but Jscript Javascript is not Jscript or Active-X, but Jscript
tries to be compatibletries to be compatible Created by NetscapeCreated by Netscape
3E-Business, Sheizaf Rafaeli
Strengths and weaknessesStrengths and weaknesses
Easy to learnEasy to learn Quick developmentQuick development Easy to debugEasy to debug Platform independentPlatform independent Small overheadSmall overhead
Limited range of built-Limited range of built-in methodsin methods
No code hidingNo code hiding Debugging and Debugging and
development tools are development tools are still lackingstill lacking
Unstable, Unstable, compatibility?compatibility?
4E-Business, Sheizaf Rafaeli
Javascript Javascript
JavaScript usually goes between the </title> tag and the </head> tag, but can go elsewhere too.
JavaScript begins with
– <script language="JavaScript">
JavaScripts end with the </script> tag. Use <NOSCRIPT> and </NOSCRIPT> Comments use the // and /* -- */ pair.
Worry about hiding scriptsWorry about hiding scripts
Javascript Javascript isis case sensitive case sensitive Is flexible about statements and white spaceIs flexible about statements and white space Scripts are evaluated as soon as the code is Scripts are evaluated as soon as the code is
encounteredencountered Functions can be defined anywhere.Functions can be defined anywhere. However they only get executed when However they only get executed when
calledcalled
7E-Business, Sheizaf Rafaeli
Javascript Javascript hiding scripts from incompatible browsershiding scripts from incompatible browsers
<html> <head> <title> Whatever </title>
<script language="JavaScript">
<!-- hide stuff from other browsers
YOUR SCRIPT HERE
// end the hiding comment -->
</script>
</head> <body>
8E-Business, Sheizaf Rafaeli
Main conceptsMain concepts
9E-Business, Sheizaf Rafaeli
Topical OutlineTopical Outline
VariablesVariables alert, prompt, document.writelnalert, prompt, document.writeln Strings as objects Strings as objects If-then branchingIf-then branching Link events (onClick, OnMouseover)Link events (onClick, OnMouseover) Opening new windows (“targeting”)Opening new windows (“targeting”) Object oriented programming, and esp. the Document Object Object oriented programming, and esp. the Document Object
ModelModel Loops, arrays and functionsLoops, arrays and functions Forms, OnChange, OnLoadForms, OnChange, OnLoad
10E-Business, Sheizaf Rafaeli
Brief overview of object-oriented programming
Built-in library of objects– Window, Math, String, Document, Form, Navigator, etc.
Objects have properties and methodsObjects have properties and methods See Javascript cheatsheet for summaries and tables, See Javascript cheatsheet for summaries and tables,
function test1(form) { if (form.text1.value function test1(form) { if (form.text1.value == "") alert('Please enter a string!');== "") alert('Please enter a string!');
else { alert("Hi "+form.text1.value+"! Form else { alert("Hi "+form.text1.value+"! Form input ok!"); }}input ok!"); }}
function test2(form) { if (form.text2.value function test2(form) { if (form.text2.value == "" || == "" ||
Why do I get JavaScript errors when using IE 3.0?When viewing a JavaScript-enabled Web site with Microsoft Internet Explorer 3.0, it's not uncommon to receive an error message in an Internet Explorer Script Error window. Microsoft released Internet Explorer 3.0 before Netscape published its proprietary JavaScript 1.1 specification. For this reason, Microsoft refers to Internet Explorer's JavaScript implementation as "Jscript", which isn't completely compatible with Netscape's JavaScript. Internet Explorer 4.0, the latest release of the browser, is compatible with the specification. If you use Internet Explorer 4.0 to view the Web site in question, you shouldn't receive an error message.
22E-Business, Sheizaf Rafaeli
DebuggingDebugging
Beginning JavaScript authors can easily debug single lines of code in Navigator. In the Location box, enter either MOCHA: or JAVASCRIPT: (including the colon) and the debugging window opens.