Java Script
JavaScript is an interpreted programming or script language from Netscape.
JavaScript is used in Web site development to such things as:
§ automatically change a formatted date on a Web page
§ cause a linked-to-page to appear in a popup window
§ cause text or a graphic image to change during a mouse rollover
Java vs. JavaScript
Java
Ø Requires the JDK to create the applet
Ø Requires a Java virtual machine to run the applet
Ø Applet files are distinct from the XHTML code
Ø Source code is hidden from the user
Ø Programs must be saved as separate files and compiled before they can be run
Ø Programs run on the server side
JavaScript
Ø Requires a text editor
Ø Required a browser that can interpret JavaScript code
Ø JavaScript can be placed within HTML and XHTML
Ø Source code is made accessible to the user
Ø Programs cannot write content to the hard disk
Ø Programs run on the client side
ECMAScript
Ø The responsibility for the development of a scripting standard has been transferred to an international body called the European Computer Manufacturers Association (ECMA).
Ø The standard developed by the ECMA is called ECMAScript, though browsers still refer to it as JavaScript.
Ø The latest version is ECMA-262, which is supported by the major browsers
Other Client-side Languages
Ø JScript is identical to JavaScript, but there are some JavaScript commands not supported in JScript, and vice versa.
Ø Internet Explorer supports JScript.
Ø Other client-side programming languages are also available to Web page designers, such as the Internet Explorer scripting language, VBScript.
Writing a JavaScript Program
The Web browser runs a JavaScript program when the Web page is first loaded, or in response to an event.
Ø JavaScript programs can either be placed directly into the HTML file or they can be saved in external files.
Ø placing a program in an external file allows you to hide the program code from the user
Ø source code placed directly in the HTML file can be viewed by anyone.
Ø A JavaScript program can be placed anywhere within the HTML file.
Ø Many programmers favor placing their programs between <head> tags in order to separate the programming code from the Web page content and layout.
Ø Some programmers prefer placing programs within the body of the Web page at the location where the program output is generated and displayed.
Ø To embed a client-side script in a Web page, use the element:
<script “text/javascript” >
script commands and comments
</script>
Ø To access an external script, use:
<script src=“url” “text/javascript”>
script commands and comments
</script>
JavaScript Syntax Issues
Ø JavaScript commands and names are case-sensitive.
Ø JavaScript command lines end with a semicolon to separate it from the next command line in the program.
Ø in some situations, the semicolon is optional
Ø semicolons are useful to make your code easier to follow and interpret
How to create JavaScript Functions
function function_name(parameters) {
JavaScript commands
}
Ø parameters are the values sent to the function (note: not all functions require parameters)
Ø { and } are used to mark the beginning and end of the commands in the function
Ø Function names are case-sensitive.
Ø The function name must begin with a letter or underscore ( _ ) and cannot contain any spaces.
Ø There is no limit to the number of function parameters that a function may contain.
Ø The parameters must be placed within parentheses, following the function name, and the parameters must be separated by commas.
JavaScript is an interpreted programming or script language from Netscape.
JavaScript is used in Web site development to such things as:
§ automatically change a formatted date on a Web page
§ cause a linked-to-page to appear in a popup window
§ cause text or a graphic image to change during a mouse rollover
Java vs. JavaScript
Java
Ø Requires the JDK to create the applet
Ø Requires a Java virtual machine to run the applet
Ø Applet files are distinct from the XHTML code
Ø Source code is hidden from the user
Ø Programs must be saved as separate files and compiled before they can be run
Ø Programs run on the server side
JavaScript
Ø Requires a text editor
Ø Required a browser that can interpret JavaScript code
Ø JavaScript can be placed within HTML and XHTML
Ø Source code is made accessible to the user
Ø Programs cannot write content to the hard disk
Ø Programs run on the client side
ECMAScript
Ø The responsibility for the development of a scripting standard has been transferred to an international body called the European Computer Manufacturers Association (ECMA).
Ø The standard developed by the ECMA is called ECMAScript, though browsers still refer to it as JavaScript.
Ø The latest version is ECMA-262, which is supported by the major browsers
Other Client-side Languages
Ø JScript is identical to JavaScript, but there are some JavaScript commands not supported in JScript, and vice versa.
Ø Internet Explorer supports JScript.
Ø Other client-side programming languages are also available to Web page designers, such as the Internet Explorer scripting language, VBScript.
Writing a JavaScript Program
The Web browser runs a JavaScript program when the Web page is first loaded, or in response to an event.
Ø JavaScript programs can either be placed directly into the HTML file or they can be saved in external files.
Ø placing a program in an external file allows you to hide the program code from the user
Ø source code placed directly in the HTML file can be viewed by anyone.
Ø A JavaScript program can be placed anywhere within the HTML file.
Ø Many programmers favor placing their programs between <head> tags in order to separate the programming code from the Web page content and layout.
Ø Some programmers prefer placing programs within the body of the Web page at the location where the program output is generated and displayed.
Ø To embed a client-side script in a Web page, use the element:
<script “text/javascript” >
script commands and comments
</script>
Ø To access an external script, use:
<script src=“url” “text/javascript”>
script commands and comments
</script>
JavaScript Syntax Issues
Ø JavaScript commands and names are case-sensitive.
Ø JavaScript command lines end with a semicolon to separate it from the next command line in the program.
Ø in some situations, the semicolon is optional
Ø semicolons are useful to make your code easier to follow and interpret
How to create JavaScript Functions
function function_name(parameters) {
JavaScript commands
}
Ø parameters are the values sent to the function (note: not all functions require parameters)
Ø { and } are used to mark the beginning and end of the commands in the function
Ø Function names are case-sensitive.
Ø The function name must begin with a letter or underscore ( _ ) and cannot contain any spaces.
Ø There is no limit to the number of function parameters that a function may contain.
Ø The parameters must be placed within parentheses, following the function name, and the parameters must be separated by commas.