UMass Lowell Dept. of Computer Science

91.461 GUI Programming I

Fall 2015 Semester, Section 201

Prof. Jesse M. Heines

Notes for Class No. 11

Introduction to JavaScript (continued) and Introduction to Forms

Tuesday, October 6, 2015

A video of this class is (or will be) posted at:   http://echo360.uml.edu/heines201516/guiprogramming1.html


Handouts and Materials


Openings / Announcements / Reminders

Long Tran — please see me


Modification to Assignment No. 5 — as posted on Piazza

Thank you to Madhu for identifying a problem with the JavaScript code that I gave you for Assignment No. 5.  When you run my code on a local Windows or Macintosh system, it works fine.  But when you run it on weblab.cs.uml.edu (a Linux system), for some reason that I do not understand jQuery.get() returns the JSON data as a string rather as an actual JSON object.  I don’t know if this is a difference in operating system defaults or a problem caused by how connections to weblab.cs.uml.edu is configured or something else.

However, I am happy to report that the problem can be solved by adding an additional parameter to the jQuery.get() function call that explicitly tells the server that you want JSON data.  That parameter is simply the string "json" (including the quotes).  Here is the modified code that you should use:

This code also differs just slightly from what I gave you earlier by eliminating the global variable story.  Instead, it passes the JSON data read from the file directly to the placeContent function.  This approach is slightly more efficient and has the advantage of eliminating a global variable, which is almost always a good thing to do.  (Thanks to Curran Kelleher for this enhancement.)  Note that this new approach requires that a story parameter be added to the placeContent function.

One last thing: it took me almost two hours to figure out the problem that Madhu identified, but ultimately the answer was in the jQuery documentation.  See page:

https://api.jquery.com/jquery.get/

This isn’t the easiest documentation to understand, but it is actually better that the documentation you will find for other JavaScript libraries.


On Coding Styles

See the Piazza posts by Curran Kelleher and me under “Why Asynchronous?”

Algorithm for sorting an array of JavaScript objects

Code posted on StackOverflow at http://stackoverflow.com/questions/979256/sorting-an-array-of-javascript-objects

My version


A rather amazing look at JavaScript

http://coodict.github.io/javascript-in-one-pic/


Class Notes

Related reading for this class:  JS&jQ:TMM Ch. 1-3


Introduction to JavaScript  (continued)

Review from last class ...

Client-side computing

New material begins here ...

Basic structure and use


A Whirlwind Look at JavaScript

Background work to prepare yourself for Assignment No. 6

Please Note

Basic Statements

Variables

Scope

Control structures

Loops

JavaScript and types — http://www.pollev.com


Functions

Function declarations vs. function expressions

Key concept:  FUNCTIONS ARE SIMPLY EXECUTABLE VARIABLES

Run all of the above functions


Functions as First-Class Objects  (Stefanov, Ch. 4)


Using Forms with Assignment No. 6

Creating Forms

Processing Forms with JavaScript

Working with the location object

http://jesseheines.com/~heines/91.461/91.461-2015-16f/461-lecs/lecture11.jsp?one=1&two=2&three=3

  1. location.search
  2. location.search.substr(1)
  3. location.search.substr(1).split("&")
  4. location.search.substr(1).split("&").length
  5. location.search.substr(1).split("&")[0].split("=")
  6. location.search.substr(1).split("&")[1].split("=")
  7. location.search.substr(1).split("&")[0].split("=")[0]
  8. location.search.substr(1).split("&")[0].split("=")[1]
  9. obj = {} ;
  10. obj
  11. obj[location.search.substr(1).split("&")[0].split("=")[0]] = location.search.substr(1).split("&")[0].split("=")[1]
  12. obj
    • Object{ one = "1" }

Demonstration

Input

http://jesseheines.com/~heines/91.461/91.461-2015-16f/461-lecs/lecture11.jsp?null

Output



This is document http://jesseheines.com:8080/~heines/91.461/91.461-2015-16f/461-lecs/lecture11.jsp.  It was last modified on Friday, August 26, 2022 at 4:09 PM.
Copyright © 2022 by Jesse M. Heines.  All rights reserved.  May be freely copied or excerpted for educational purposes with credit to the author.