230 likes | 267 Views
Brief Look InTo JavaScript. Dr. Thomas Hicks Computer Science Department Trinity University. JavaScript developed by Netscape version 1.2 (Netscape 4.0) Netscape considered authority Not all versions are the same. David Flannigan.
E N D
Brief Look InTo JavaScript Dr. Thomas Hicks Computer Science Department Trinity University
JavaScript • developed by Netscape • version 1.2 (Netscape 4.0) • Netscape considered authority • Not all versions are the same David Flannigan
“JavaScript is a lightweight, interpreted, programming language with rudimentary object-oriented programming capbilities”. David Flannigan
JavaScript is syntactically similar to Java and C++! Similarities end there!
JavaScript is powerful because a client-side version has been embedded within some of the more recent browsers! Netscape & Internet Explorer
JavaScript is a case sensitive language! while (not While, WHILE, etc.) JavaScript ignores white space! (space, tab, newline between tokens)
JavaScript Semicolans at the end of each statement (optional if one statement to a line! A = 5; B = 6; A = 5 B = 6
JavaScript Comments // ------------- till the End of Line /* ------------------------------------------------------------------------ */
HTML Tag Set <SCRIPT LANGUAGE = "JavaScript"> </SCRIPT>
Code JavaScript 1] document.write(‘Hello World’)! 2] multiple <SCRIPT> tags 3] Factorial solution
J1.html <HTML> <HEAD> <TITLE>J1.html</TITLE> </HEAD> <BODY> <SCRIPT LANGUAGE = "JavaScript"> document.write ("Hello World"); </SCRIPT> <CENTER><P><BR> <BR> <B><I><FONT COLOR="#000080"><FONT SIZE=+2>JavaScript Page </FONT></FONT></I></B></P></CENTER> </BODY> </HTML>
J2.html <HTML> <HEAD> <TITLE>J2.html</TITLE> </HEAD> <BODY> <SCRIPT LANGUAGE = "JavaScript"> document.write ("Hello World"); </SCRIPT> <CENTER><P><BR><B><I><FONT COLOR="#000080"><FONT SIZE=+2> Welcome to the Web </FONT> </FONT></I></B></P></CENTER> <SCRIPT LANGUAGE = "JavaScript"> document.write ("ByeBye World"); </SCRIPT> </BODY> </HTML>
J3.html <HTML> <HEAD> <TITLE>J3.html</TITLE> </HEAD> <BODY> <SCRIPT LANGUAGE = "JavaScript"> document.write('<FONT COLOR="#000080"><H1><CENTER> Factorial Page </CENTER></H1></FONT>'); for (i=1, Fact=1; i <= 10;i +=1, Fact *= i) { document.write (i + '! = ' + Fact); document.write ('<br>'); } </SCRIPT> </BODY> </HTML>
If JavaScript could only do simple program, such as Factorial, we would not bother with it! Power: browser & document based objects document.write()
Several different JavaScript objects have control over the browser! The JavaScript event handler can enable the user to control the actions and directions of the browser!
The FORM object is very important in JavaScript interaction! Button, Checkbox, Hidden, Radio, Reset, Select, Password, Text, Text Object, etc.
CGI? Traditional HTML forms were used with CGI scripts. JavaScript is more platform independent and is more practical in some cases!
CGI vs JS Calculator App Using CGI, the server would have to be contacted each time the user clicked a button or entered a value! YUK!
Cookies? A Cookie is a term coined by Netscape to represent a chunk of code that is downloaded (from the server) to the client machine. Cookies can be stored temporarily or permanently!They transmit state information, relative to the web, back and forth with the original server!Cookies can be good!
Cookies http://my.yahoo.com A cookie used to remember the user preferences!
JavaScript In many cases, the combination of browser control and cookies enable JavaScript to completely replace CGI!
JavaScript 1] can not read from files 2] can not write to files 3] has no graphics support! 4] can not support networking
Server-Side JavaScript • A document that contains server-side JavaScript is requested by the client! • The requested document is generated and compiled, on the server, into binary form and sent to the client! (Efficiency) • Has File and Database Object Types!