JavascriptCS 110 Fall 2007JavascriptThe BROWSER scripting language.Similar syntax to java.History: Netscape created to allow dynamic web pages.Uses: Many, here are a couple: verifying and reacting to user input, updating page without making user wait Javascript tutorial: http://www.w3schools.com/js/js_intro.aspAlert box sample: http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm<html><head><script type="text/javascript">function disp_confirm(){var r=confirm("Press a button");if (r==true) { document.write("You pressed OK!"); }else { document.write("You pressed Cancel!"); }}</script></head><body><input type="button" onclick="disp_confirm()" value="Display a confirm box" /></body></html>CS 110 Fall 2007Can also put javascript in a file external to the html:<html><head><script src="confirm.js"></script></head><body><input type="button" onclick="disp_confirm()" value="Display a confirm box" /></body></html>confirm.js:function disp_confirm(){var r=confirm("Press a button");if (r==true) { document.write("You pressed OK!"); }else { document.write("You pressed Cancel!"); }}See sample at http://www.cs.usfca.edu/~wolber/jsSamples/confirm2.htmlCS 110 Fall 2007Advanced UsesDOM – Document Object ModelYour program can get at the elements in the html.So, for instance, you can sort a list in different ways. A big data structure representing the html page.AJAX – Asynchronous javascript and xmlCall a server to get data, asynchronously.User doesn’t have to wait for call to web service to completeVacation fun: Write mastermind with html and javascript!Html pageJava scriptExternal Web
View Full Document