A video of this class is (or will be) posted at: http://echo360.uml.edu/heines201516/guiprogramming1.html
https://docs.google.com/forms/d/1dHTYaWtph67108xNBn2XA5ezyr3XdrqoGjWep86Nxgk/viewform
Aso of Wednesday, October 14, at 11:00 AM, only 16 students had completed the form
As of this morning, Thursday, October 15, at 8:45 AM, 18 students had completed the form
This course would be better if ...
I would learn more from this course if ...
Prof. Heines would be a more effective teacher if ...
Please write any additional comments (positive or negative) and/or suggestions you have for improving this course. These may relate to any aspect of the course at all or anything that I could do to help you learn.
Related reading for this class: JS&jQ:TMM Ch. 4, 5 & 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() ) ;form tag
method attribute: post or getaction 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 tagsUsing Buttons
Working 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.searchlocation.search.substr(1)location.search.substr(1).split("&")location.search.substr(1).split("&").lengthlocation.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/lecture13.jsp
Output
Global Methods (Functions) — Deitel Fig. 11.13 on p. 370 (1st ed.), Fig. 10.8
on p. 341 (2nd ed.), Fig. 9.9 on p. 345 (4th ed.)
Object reference page extremely useful: http://msdn.microsoft.com/en-us/library/htbw4ywd(VS.85).aspxReference: Deitel, P.J. & Deitel, H.M. Internet & World Wide Web How To Program, 4th edition. pp. 345-346.
Global
FunctionDescription escapeTakes a string argument and returns a string in which all spaces, punctuation, accent characters and any other character that is not in the ASCII character set are encoded in a hexadecimal format that can be represented on all platforms. unescapeTakes a string as its argument and returns a string in which all characters previously encoded with escape are decoded. evalTakes a string argument representing JavaScript code to execute. The JavaScript interpreter evaluates the code and executes it when the eval function is called. This function allows JavaScript code to be stored as strings and executed dynamically. Note: It is considered a serious security risk to use evalto process any data entered by a user because a malicious user could exploit this to run dangerous code.isFiniteTakes a numeric argument and returns trueif the value of the argument is notNaN,Number.POSITIVE_INFINITYorNumber.NEGATIVE_INFINITY(values that are not numbers or numbers outside the range that JavaScript supports)—otherwise, the function returnsfalse.isNaNTakes a numeric argument and returns trueif the value of the argument is not a number; otherwise, it returnsfalse. The function is commonly used with the return value ofparseIntorparseFloatto determine whether the result is a proper numeric value.parseFloatTakes a string argument and attempts to convert the beginning of the string into a floating-point value. If the conversion is unsuccessful, the function returns NaN; otherwise, it returns the converted value (e.g.,parseFloat("abc123.45")returnsNaN, andparseFloat("123.45abc")returns the value123.45).parseIntTakes a string argument and attempts to convert the beginning of the string into an integer value. If the conversion is unsuccessful, the function returns NaN; otherwise, it returns the converted value (e.g.,parseInt("abc123")returnsNaN, andparseInt("123abc")returns the integer value 123). This function takes an optional second argument, from 2 to 36, specifying the radix (or base) of the number. Base 2 indicates that the first argument string is in binary format, base 8 indicates that the first argument string is in octal format and base 16 indicates that the first argument string is in hexadecimal format.
HTML5
CSS3
JavaScript
jQuery
Photo Credits
- Building Scaffolding — http://blog.fieldid.com/wp-content/uploads/scaffolding_example.jpg
- Pine Tree — http://www.northshoregarden.com/wp-content/uploads/2011/12/pine_tree-11921.jpg
- Child Decorating Christmas Tree — http://www.wallcoo.net/holiday/2008_family_christmas_fun_1920x1200/images/Family_Christmas_fun_094_008.jpg
- Christmas Celebration — http://www.wallcoo.net/holiday/2008_Family_Christmas_celebration_1920x1200/wallpapers/1920x1200/Family_Christmas_Celebration_FAN2019853.jpg
- Lots & Lots of Presents — http://blogs.babble.com/being-pregnant/files/2011/12/stxmco001christmas_tree_and_presents1.jpg
As you surely realize by now, JavaScript is no longer your father’s (or your grandfather’s) toy language for making little things happen change on web pages
The key to using JavaScript, however, is not the language itself
[figure source: jQuery: Novice to Ninja, by Castledine & Sharkie, p. 12]
The following examples and page references in orange are from jQuery: Novice to Ninja, by Castledine & Sharkie
Examples in jQuery: Novice to Ninja and JS&jQ:TMM Ch. 4
$(document).ready( function() { ... } ) ; // pp. 18-19console.log( $('#celebs tr').length) ) ; // p. 23console.log( $('#celebs tbody tr').length) ) ; // adding semantics for specificity, p. 23console.log( $('#celebs tbody tr:even').length) ) // using a filter, p. 24var fontSize = $('#celebs tbody tr:first').css('font-size') ; // p. 25
$('#celebs tbody tr:even').css('background-color', '#dddddd') ; // p. 26
$('#celebs tbody tr:even').css('background-color', '#dddddd') ; // p. 27$('#celebs tbody tr:even').css('color', '#66666') ;
backgroundColor instead of background-color$('#celebs tbody tr:even').css('background-color', '#dddddd').css('color', '#66666') ;
$('#celebs tbody tr:even').css( // p. 28
{ 'background-color' : '#dddddd',
'color' : '#666666' } ) ;
Adding and removing classes (pp. 30-31)
$('div').addClass('class_name') ;
$('div').addClass('class_name1 class_name2 class_name3') ;
.zebra { /* a class for zebra striping */
background-color: #dddddd ;
color: #666666 ;
}
$('#celebs tr:even').addClass('zebra') ;
$('#celebs tr.zebra').removeClass('zebra') ;
submit — triggered when the form is submitted
focus — triggered when a control gains focus
blur — triggered when a control loses focusclick — triggered when a control is clickedchange — triggered whenever a control is changed
Using the jQuery submit() event handler
1 $(document).ready( function() {
2 tblInitializer.initialize() ;
3 tblGenerator.populateMultiplicationTable_jQuery( "#placeholder", true ) ;
4 $('#frm').submit( function() { // trap the submit event *before* the action is executed
5 return validateForm() ; // true = allow action to proceed, false = inhibit action
6 } ) ;
7 } ) ; // end ready
Writing validation tests
val() functionhtml() functionisNaN() functionreturn statement efficiently
$( '#' + str ) trickRemember the three pillars of good error messages:
Initializing form fields
isNaN() function? xBegin <= xEnd and yBegin <= yEnd