JavaScript Big fun with JavaScript in the real world Very early in the morning February 17, 2000
Why JavaScript? You can’t deal with a Java applet You want more glitz on your pages You need some active widgets that HTML does not have You want on-the-fly calculations User’s need the option to do database lookups without submitting the HTML form they are filling out
Why NOT JavaScript? Some users have turned off JavaScript in their browser Semi-broken implementations Some browsers will never support it You might have to special case the code depending on which browser the user has… With JavaScript, you are signing up for more maintenance and testing costs
The basics JavaScript lives in the HTML page surrounded by the tags <script language="Javascript"> <!-- hide this from lame browsers Your code goes here // --> </script> You get variables, some event handling, and the chance to open new windows without a trip back to the web server
Debugging alert("some string") is about as good as it gets Do yourself a favor and edit the HTML page locally so you are not uploading it to the web server each time you change something while debugging Typing javascript: into the location in Netscape gets you a console
Example: Glitz Event handlers let you animate things <a href="/foo" onMouseOver="funct()" onMouseOut="funct2()"<a> OnClick, OnLoad, OnSubmit, etc. let you attach functions to elements of a page You can change element of the page from the event handler function
...Example: Glitz Javascript functions can stuff values into fields, open windows, or change the images Elements on a page can be addressed like this: document.forms[0].elements.foo.value See http://www.techmart.umn.edu/
Example: Calculations Running totals are a natural addition to many sorts of forms Unfortunately, JavaScript’s floating point number support is less than optimal See the wretched JAWS timesheet http://pong.software.umn.edu/ See the well-loved FormsNirvana POT http://nirvana.fss.umn.edu/
Example: DataBase lookups Nobody can remember all the job titles or department names at the University You might want to spawn a child window to do a lookup and auto-fill an HTML form field. Example: the conflict of interest form at http://nirvana.ospa.umn.edu/
Summary Do not require the use of JavaScript. Give the JavaScript-challenged equal access to your site Debug carefully. Alert() is your friend. Test on multiple platforms (various browser versions on Unix, Mac, & PC) JavaScript is not harmful when used under controlled conditions