------------------------------------- Lab 12 Material - November 13th, 2008 ------------------------------------- .. @ order of sql? Reminder: office hours tonight, 9-11pm; hw due at 5pm on Friday. --- Objective: expose you to JavaScript and JS troubleshooting. General JS resources: http://www.w3schools.com/js/ http://devguru.com/technologies/javascript/home.asp --- Files for this lab are in svn, at: http://class.ged.idyll.org/svn/files/lab-12/ or you can copy them from ~ctb/lab-12/ on the CSE cluster. --- Common problems (hat tip to Taylor Marshall): :: '' == '0' //false 0 == '' // true 0 == '0' // true (== and != are not symmetric, so weird stuff can happen as above; this is also possible in Python, note!) Recommend using === and !== operators to avoid such tomfoolery. In the above examples, all statements would evaluate to false using ===. JavaScript examples ------------------- Simple JS (`page `__, `source `__) : :: <-- Hide your JavaScript from non-JS users (`page `__, `source `__) : :: Load JavaScript code from another file (`page `__, `source `__ and `JS source `__) : :: Grouping JS statements into blocks with squigglies (`page `__, `source `__) : :: Basic JS prompts (`page `__, `source `__) : :: alert("something happened!"); confirm("may I delete all your files?"); prompt("some question","defaultvalue"); Functions, head/body separation, and element events (`page `__, `source `__) : ::
'undefined' implicit conversion to strings, & errors (`page `__, `source `__) : :: document.write("this.bar is: " + this.bar) document.write("

foo is: " + foo); document.write("

and hello, world!"); (Go look at the Firefox error console.) Simple object-oriented programming, and iteration over bags o' properties (`page `__, `source `__) : :: function some_object_method(param) { document.write("hello! This is SomeObject's other param: "); document.write(this.what); document.write("

and this is my method param:"); document.write(param); } function SomeObject(what, other_param) { this.foo = "hello"; this.what = other_param; this.method = some_object_method; } ///// x = new SomeObject("world", 2); document.write(x.foo + " " + x.what + "

"); x.method("argument to SomeObject.method"); for (z in x) { document.write('

z is ' + z); document.write('

x[z] is ' + x[z]); } Working with HTML elements (`page `__, `source `__) : ::

New title:
--- Group exercises --------------- There are several files with a variety of problems between them, in `lab-12/exercises/ `__. Fix the problems! .. @@ wrong stuff: .. @@ syntax error, no semicolon .. @@ .. @@ no , when loading external file .. @@ multi find .. @@ no find .. @@ determine properties, CSS mod .. @@ submit stuff!