Transcript JavaScript
JavaScript
•
•
•
•
•
•
Overview
Developer Essentials
How to Code
Language Constructs
The DOM concept- API, (use W3C model)
Objects
– properties
• Methods
• Events
• Applications;
– Rollovers
– Smart Forms
– Cookies
Overview
• A programming Language that adds
interactivity to Web Pages
– a scripting language
• A JS script is a program that is included in
an HTML page
• A JS script is interpreted by Web browsers
• Related Scripting Languages
– VbBasic, ActionScript:Flash, Adobe :JScript, Mac & .NET
Background
• Used to be “Live Script”
– Plus more!
What can JavaScript do
• Create an active user interface
• Validate user input on Forms
• Create HTML pages on the fly
• Control Web Browsers
Can’t do
• Talk to databases
• Write to files
• Keep a counter or Track of State!
Applications
We use JavaScript for:
Tailoring the experience
– Different content based on criteria
• Extending the experience
– Dynamic pages
– User interface elements eg; pop-up menus
• Validating input
– Pre processing forms
JScript Language
• Characteristics
– where to place code
– statements
• Programming Concepts
– Sequence
– Selection
– Iteration
• Server side vs Client side
JS- Statements
•
•
•
•
•
Invoke Object Methods
Initialise or Define Variables
Manipulate Variables
Invoke a Function
Make Programming Decisions
JS- Statements cont.
• When the HTML Document Loads
• Immediately after the Doc Loads
• Respond to USER Action
– Event Handler
• When invoked by other Script Statements
JS- example
<html>
<head>
<title>My First JavaScript Script</title>
<style type=“text/css”>
.highlight {font-weight: bold}
</style>
</head>
<body>
<h1> Let the Scripting begin ......</h1>
<script type=“text/javascript” language=“javascript”>
<!-- hide script form old browsers
document.write(“This browser version” + navigator.appVersion);
document.write(“of <span class=‘highlight’>” + navigator.appName +
“</span>.”);
//end the script hiding -- >
</script>
</body>
</html>