JAVASCRIPT TIPS. REMEMBER JAVASCRIPT IS VERY, VERY CASE SENSITIVE.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Javascript It’s not JAVA. What do these all have in common?
1 Programmer-Defined Functions Functions allow program modularization Variables declared in function are local variables Only known inside function in.
Python, CGI November 23, Unit 8. So Far We can write programs in Python (in theory at least) –Conditionals –Variables –While loops We can create a form.
Chapter 20 Thinking Big: Functions. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Anatomy of a Function Functions are packages for.
Python November 14, Unit 7. Python Hello world, in class.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
. If the PHP server is an server or is aware of which server is the server, then one can write code that s information. –For example,
JavaScript onLoad getElement. onload Using JavaScript to create content No user input Comes up when page LOADS [redo Koozebane; random picture]
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
JavaScript Events and Event Handlers 1 An event is an action that occurs within a Web browser or Web document. An event handler is a statement that tells.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
JavaScript Form Validation
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
INTERNET APPLICATION DEVELOPMENT For More visit:
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
Department of Information Technology e-Michigan Web Development 0 HTML Form Creation in the Vignette Content Management Application.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
by Chris Brown under Prof. Susan Rodger Duke University June 2012
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
JavaScript Lecture 6 Rachel A Ober
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
Review IDIA 619 Spring 2013 Bridget M. Blodgett. HTML A basic HTML document looks like this: Sample page Sample page This is a simple sample. HTML user.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Tutorial 10 Programming with JavaScript
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
VBA Lab 2 I ns.Samia Al-blwi. Visual Basic Grammar Object: Visual Basic is an object-oriented language. This means that all the items in Excel are thought.
Using Client-Side Scripts to Enhance Web Applications 1.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
Arrays, date, random. Declared Variables Explicitly define them Can give them starting values Figures out type Case sensitive var x = 5; (note: this is.
ITBP 119 Algorithms and Problem Solving Section 2.1 Installing software Section 2.2 First Programs Section 2.3 Variables.
The Grammar of JavaScript.  Each line of a script is a statement  An instruction that JavaScript can evaluate (make sense of)  Ends with a semicolon;
Keeping it Neat: Functions and JavaScript Source Files Chapter 7.
HTML Form and PHP IST Review of Previous Class HTML table and PHP array Winner is chosen randomly using rand() function.
David Stotts Computer Science Department UNC Chapel Hill.
CONDITIONALS DATE CHANGES OUTSIDE FORMS. CONDITION ALS.
Nonvisual Arrays by Chris Brown under Prof. Susan Rodger Duke University June 2012.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
JavaScript VARIABLES AND DATA TYPES. OUTPUT WITHOUT ALERT OR FORM CONSOLE.LOG();
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
JavaScript Functions. CSS Inheritance Which formatting applies? x y z input { display: block; } input.pref { background:red; } If you have a selector.
Expressions and Data Types Professor Robin Burke.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
 Collection of statements that can be invoked as a unit  Can take parameters  Can be used multiple times  Can call without knowing what they do or.
Tutorial 10 Programming with JavaScript
Variables and Data Types
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
JavaScript functions.
JavaScript Arrays Date
JavaScript Functions.
Web Programming– UFCFB Lecture 17
More Selections BIS1523 – Lecture 9.
Console.
Javascript: variables and parameters
JavaScript Functions.
Reviewing key concepts
Programming in JavaScript
Variables and Data Types
Remembering lists of values lists
JavaScript onLoad arrays
Programming in JavaScript
Chapter 20: Programming Functions
Python Basics with Jupyter Notebook
JavaScript functions.
Writing to the Page Formatting Forms
Intro to Programming (in JavaScript)
Presentation transcript:

JAVASCRIPT TIPS

REMEMBER JAVASCRIPT IS VERY, VERY CASE SENSITIVE

RESERVED WORDS List by category List by category List by category List by category Alphabetical list under resources Alphabetical list under resources

JAVASCRIPT CONSOLE Shows errors Shows errors Lets you write messages and intermediate results Lets you write messages and intermediate results console.log ( whatever helps);

USING JSFIDDLE Validation Validation Testing Testing Cut and paste Cut and paste Add HTML and CSS if you are having problems Add HTML and CSS if you are having problems

KEY CONCEPTS: VARIABLES AND FUNCTIONS

VARIABLES A place to hold a value A place to hold a value Mailbox: know where to pick up my mail; don’t know what’s in it Mailbox: know where to pick up my mail; don’t know what’s in it How to define? How to define? var name; var name = initial-value;

FUNCTION: COLLECTION OF INSTRUCTIONS HTML JAVASCRIPT (function.js) function doit () { alert(“Hi!”); }

WHAT WE WANT TO DO

FORM WITH INPUT, BUTTON, OUTPUT HTMLJavaScript

ADD DATA HTMLJavaScript

PUSH BUTTON AND INPUT DATA SENT TO JAVASCRIPT HTMLJavaScript

PARAMETERS Just a special type of variable Just a special type of variable Something that you hand to the function Something that you hand to the function Q: Many users: how do you name? Q: Many users: how do you name? A: Give it its OWN names to use locally A: Give it its OWN names to use locally Q: How do you match up? Q: How do you match up? A: By POSITION A: By POSITION

FUNCTION WITH PARAMETERS HTML JAVASCRIPT (function.js) function doit (a,b) { var c = a*b); alert(“product is ”+c); }

JAVASCRIPT USES THE DATA TO CREATE A NEW RESULT HTMLJavaScript

AND MOVES IT TO THE OUTPUT LOCATION HTMLJavaScript

RETURN VALUE return (value); Want to get information BACK to HTML Want to get information BACK to HTML With a return, the function has a VALUE With a return, the function has a VALUE Can be used anywhere you can use a constant or variable Can be used anywhere you can use a constant or variable Alert Alert Assignment statement Assignment statement Can only change one thing with a return Can only change one thing with a return

FUNCTION WITH RETURN HTML JAVASCRIPT (function.js) function doit (a,b) { var c = a*b; return(c); }

CHANGING MORE THAN ONE THING If you have two things that you want to change Can change them in the function Usually do NOT return value Can only use such a function in one place

DOING INTERESTING THINGS WITH JAVASCRIPT

ASSIGNMENT STATEMENTS target = new-value; CHANGE the value of the target variable TO the new-value CHANGE the value of the target variable TO the new-value new-value can be a constant, a variable, or an expression new-value can be a constant, a variable, or an expression x = 3; x = y; x = x+ 5;

ARRAYS Collection of related information Collection of related information Easy way to choose between items Easy way to choose between items var array = [ “A", "B", “F", "G" ]; var array = [ “A", "B", “F", "G" ]; array[index] array[index] Example: user enters number, you return that month Example: user enters number, you return that month

RANDOM SELECTION Choose between options randomly Choose between options randomly var n = Math.random(); [Math is a collection of functions] If you use it twice, you get two different values. Need to save it to reuse!

CONVERTING RANDOM TO INTEGER Often useful to convert that random number to an integer Often useful to convert that random number to an integer Index into array! 0->1 needs to be changed to 0->3 (or any other number) 0->1 needs to be changed to 0->3 (or any other number) var biggerNumber = n*4; gets the range correct var biggerNumber = n*4; gets the range correct But only want integer: But only want integer: Math.floor returns the largest integer less than the value var biggerInteger = Math.floor(n*4); var biggerInteger = Math.floor(n*4);

PUTTING CONTENT WITHIN TAGS General form: context.element.attribute So far we have form-name.input-id.value form-name.input-id.value form-name.img-id.src form-name.img-id.src