javascript
DESCRIPTION
TRANSCRIPT
C G S 2 8 3 5 Web Dev
C G S 2 8 3 5 Web Dev
Programming Languages
• All have…– Variables, data types, assignment– Arithmetic, relational, and logical operators, and
expressions– Control structure: if-then, while, loops, iteration– Program structure: functions, objects, methods– Arrays and strings– Input and Output
C G S 2 8 3 5 Web Dev
What is JavaScript?
• JavaScript is a programming/scripting language designed for the Web
• Javascript is interpreted not compiled• JavaScript is not Java• JavaScript provides interactivity for Web pages• JavaScript may be embedded in HTML or
referenced from HTML (like CSS)• JavaScript is forgiving and easy to use
C G S 2 8 3 5 Web Dev
JavaScript is Object-Oriented
• JavaScript uses objects that have attributes and methods
The DOM (Document Object Model)
bgColor is an attribute of the document objectdocument.bgColor=“#888888”;
write is a method in the document objectdocument.write(“Hello Earl!”);
C G S 2 8 3 5 Web Dev
JavaScript is typically used to enhance a Web interface
http://pic.fsu.edu/courses/wdp/current/tutorials/javascript/examples/mouseover2.html
http://pic.fsu.edu/courses/wdp/current/tutorials/javascript/coolmenu/
http://javascript.internet.com/toc.html
http://sixrevisions.com/rapid-development/10_ajax_effects_website_fanciness/
Javascript is a key element in the popular AJAX programming methodology.Javascript code can reference Javascript libraries such as jQuery.
C G S 2 8 3 5 Web Dev
JavaScript Embedded in HTML• In the html <body>
C G S 2 8 3 5 Web Dev
JavaScript Embedded in HTML• In the html <body>
http://www.pic.fsu.edu/courses/wad/tutorials/javascript/examples/doc_write.html
C G S 2 8 3 5 Web Dev
JavaScript Embedded in HTML• In the html <head>
http://www.pic.fsu.edu/courses/wad/tutorials/javascript/examples/function.html
C G S 2 8 3 5 Web Dev
Working with Variables
http://www.pic.fsu.edu/courses/wad/tutorials/javascript/examples/variables.html
C G S 2 8 3 5 Web Dev
Working with Variables
http://www.pic.fsu.edu/courses/wad/tutorials/javascript/examples/variables2.html
C G S 2 8 3 5 Web Dev
HTML Forms
• Javascript can collect user input through HTML forms.
http://www.pic.fsu.edu/courses/wad/tutorials/javascript/examples/form_objects.html
http://www.pic.fsu.edu/courses/wad/tutorials/javascript/examples/change_background.html
http://www.w3schools.com/html/html_forms.asp
C G S 2 8 3 5 Web Dev
http://www.pic.fsu.edu/courses/wad/tutorials/javascript/examples/form_adder.html http://www.pic.fsu.edu/courses/wad/tutorials/javascript/examples/form_adder2.html
Calling a function from a form
v1 and v2 are two variables being passed into function add
this.form.v1.value gets the value the user typed in the v1 textbox on the form in this document
The button calls the function add when it is clicked (onclick)
C G S 2 8 3 5 Web Dev
if – elseif - else
http://www.pic.fsu.edu/courses/wad/tutorials/javascript/examples/if_else.html