A video of this class is (or will be) posted at: http://echo360.uml.edu/heines201516/guiprogramming1.html
Remember: We do not have class next Tuesday, as that is a Monday class schedule
https://docs.google.com/forms/d/1dHTYaWtph67108xNBn2XA5ezyr3XdrqoGjWep86Nxgk/viewform
Related reading for this class: JS&jQ:TMM Ch. 1-3
function
statementnull
, sort of ...
null
using ==
, you get true
, but you can’t differentiate that from a truly null
parameternull
using ===
, you get false
, which allows you to differentiate unsupplied parameters from truly null
parameters
if ( typeof( param ) === "undefined" ) { ... }
true
for undefined parametersfunction test( a, b, c ) { ... }
var test = function( a, b, c ) { ... }
arguments
object holds all the parameters pass to a function
arguments
is “array-like,” but it is not an instance of the Array
typearguments.length
returns the number of parameters passed to a functionhead
sectionreturn
statement, but again there is no declared type for the
functionFunction declarations vs. function expressions
function sum_v1( n1, n2 ) {
return n1 + n2 ;
} ;
document.writeln( sum_v1( 1, 2 ) ) ;
var sum_v2 = function( n1, n2 ) {
return n1 + n2 ;
} ;
document.writeln( sum_v2( 3, 4 ) );
var sum_v2a = function( n1, n2 ) {
return "sum = " + n1 + n2 ;
} ;
document.writeln( sum_v2a( 3, 4 ) ) ;
var sum_v2b = function( n1, n2 ) {
return "sum = " + ( n1 + n2 ) ;
} ;
document.writeln( sum_v2b( 3, 4 ) ) ;
var sum_v3 = function () {
return "sum = " + ( arguments[0] + arguments[1] ) ;
} ;
document.writeln( sum_v3( 5, 6 ) ) ;
var sum_v4 = function () {
var sum = 0 ;
for ( var k = 0 ; k < arguments.length ; k++ ) {
sum += arguments[k] ;
}
return "sum = " + sum ;
} ;
document.writeln( sum_v4( 7, 8, 9 ) ) ;
Key concept: FUNCTIONS ARE SIMPLY EXECUTABLE VARIABLES
var sum_v5 = function() {
sum_v5 = function() { return "I'm bad!" } ;
return "I'm good!" ;
} ;
document.writeln( sum_v5() ) ;
document.writeln( sum_v5() ) ;
Run all of the above functions
form
tag
method
attribute: post
or get
action
attribute: a URL for the program or script or page that will process the forminput
tag
button
, checkbox
, file
, hidden
, image
, password
, radio
, reset
, submit
, or text
hidden
and image
display elements with which the user can interacthidden
passes information to the form processor outside the user’s controlimage
is really a variant of the submit tag (discussed below)value
attribute: the component’s corresponding default text (changed when the user enters new text)select
attribute: controls whether the element is initially selected (changed when the user clicks radio buttons, check boxes, etc.)id
attribute: the component’s name for referencing via scripts within the current pagename
attribute: the component’s name for referencing via scripts in the form processor pageid
and name
attributes even though they’re both the same
<input type="text" name="lastname" id="lastname" size="40">
select
tag
option
tagssubmit
and reset
tagsWorking with the location
object
http://jesseheines.com/~heines/91.461/91.461-2015-16f/461-lecs/lecture12.jsp?one=1&two=2&three=3
location.search
location.search.substr(1)
location.search.substr(1).split("&")
location.search.substr(1).split("&").length
location.search.substr(1).split("&")[0].split("=")
location.search.substr(1).split("&")[1].split("=")
location.search.substr(1).split("&")[0].split("=")[0]
location.search.substr(1).split("&")[0].split("=")[1]
obj = {} ;
obj
Object{ }
obj[location.search.substr(1).split("&")[0].split("=")[0]] = location.search.substr(1).split("&")[0].split("=")[1]
obj
Object{ one = "1" }
Input
http://jesseheines.com/~heines/91.461/91.461-2015-16f/461-lecs/lecture12.jsp
Output