JavaScript Programming Labs

Slides:



Advertisements
Similar presentations
Emerging technology and Platform#3: JavaScript Bina Ramamurthy.
Advertisements

JavaScript 101 Lesson 01: Writing Your First JavaScript.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
Emerging Applications and Platform#3: JavaScript Bina Ramamurthy 7/4/2015CSE651C, B. Ramamurthy1.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
DOM and JavaScript Aryo Pinandito.
JavaScript is a client-side scripting language. Programs run in the web browser on the client's computer. (PHP, in contrast, is a server-side scripting.
JavaScript Programming B.Ramamurthy 6/113/2014B. Ramamurthy CSE6511.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
12/7/2015B.Ramamurthy1 Exam2 Review CSE111 B.Ramamurthy.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
CO1552 – Web Application Development Further JavaScript: Part 1: The Document Object Model Part 2: Functions and Events.
1/25/2016B.Ramamurthy1 Exam3 Review CSE111 B.Ramamurthy.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
1 The Document Object Model. 2 Objectives You will be able to: Describe the structure of the W3C Document Object Model, or DOM. Use JavaScript to access.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Precedence Operators Error Types
Introduction to.
DHTML.
Build in Objects In JavaScript, almost "everything" is an object.
Javascript and Dynamic Web Pages: Client Side Processing
Programming Web Pages with JavaScript
Applied Component I Unit II Introduction of java-script
>> JavaScript: Document Object Model
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Unit M Programming Web Pages with
Bare boned notes.
CSE 102 Introduction to Web Design and Programming
HyperText Markup Language
Tek Raj Chhetri Code for Humans not for machine.
HTML & teh internets.
Human Computer Interaction
JavaScript is a programming language designed for Web pages.
Unit M Programming Web Pages with
W3C Web standards and Recommendations
Key concepts of Computing
JavaScript functions.
The Document Object Model (DOM) is a W3C standard.
Exam3 Review CSE111 B.Ramamurthy 7/28/2018 B.Ramamurthy.
Revision.
Website Design 3
DHTML.
CSS – Cascading Style Sheet DOM – Document Object Model
Google Maps: A Short How-to
DHTML Javascript Internet Technology.
Web Programming A different world! Three main languages/tools No Java
Your 1st Programming Assignment
Exam3 Review CSE111 B.Ramamurthy 11/24/2018 B.Ramamurthy.
Introduction to JavaScript
DHTML Javascript Internet Technology.
Introduction to Programming the WWW I
Introduction to JavaScript
Intro to Web Development First Web Page
Javascript and JQuery SRM DSC.
HTML5 and Local Storage.
JavaScript Basics What is JavaScript?
Chapter 7 Event-Driven Pages
HyperText Markup Language
JavaScript is a scripting language designed for Web pages by Netscape.
Introduction to Programming and JavaScript
CNIT 133 Interactive Web Pags – JavaScript and AJAX
slides courtesy of Eric Roberts
Web Programming and Design
AJAX By Prof. B.A.Khivsara
Presentation transcript:

JavaScript Programming Labs B.Ramamurthy B. Ramamurthy CSE651 1/11/2019

Why JavaScript? (contd.) JSON: Javascript Object notation JSON based data exchange; JSON based webservices From www.json.org JSON is built on two structures: A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array. An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence. These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages also be based on these structures. B. Ramamurthy CSE651 1/11/2019

Try this code: in notepad++ save as ex3.html <!DOCTYPE html> <html> <head> <title>Google Maps Example</title> <script src=" https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"> </script> <script> var map; function initialize() { var mapOptions = { zoom: 8, center: new google.maps.LatLng(42.9, -79.8), mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); } </head> <body onload="initialize()"> <div id="map_canvas" style="width: 500px; height: 300px"></div> </body> </html> B. Ramamurthy CSE651 1/11/2019

More lat.long Now change the lat,long as shown below: google.maps.LatLng(12.9, 77.56) Change the lat long to (27.9, 86.9) B. Ramamurthy CSE651 1/11/2019

On to JavaScript Lets learn some more features of JS and also how to power an application using JS functions. Also we want to structure our applications in a modular fashion: no mix of HTML, CSS and JS: three separate files Lets do that for this Google Map example B. Ramamurthy CSE651 1/11/2019

HTML+JS Lets add some widgets like buttons and textboxes and power them using JS functions Only that we will separate the widgets and function in html and js file separately B. Ramamurthy CSE651 1/11/2019

ex4.html <!DOCTYPE html> <html> <head> <title></title> <script> </script> </head> <body> <div id="auto_panel" style="width: 500px; height: 300px; background-color: lightblue;"></div> </body> </html> What do you? How will you center this panel/canvas for displaying the widgets? B. Ramamurthy CSE651 1/11/2019

Lets add some widgets Add a button within the dvi tags as shown below: understand the various properties of the button widget. <div id="auto_panel" style="width: 500px; height: 300px; background-color: lightblue;"> <input type="button" name="b1" value="Click Here" onclick=''/> </div> B. Ramamurthy CSE651 1/11/2019

Lets respond to the click Lets write a simple javascript and link it to the main html code Simple Javascript file has these components Data area Functions Lets add js function to the button. Save the code below in ex4.js and modify ex4.html to link to this file (as shown in the next slide) function first() { alert (" Button was clicked!"); } B. Ramamurthy CSE651 1/11/2019

Changes in ex4.html <script type="text/javascript" src="ex4.js"> </head> <body> <div id="auto_panel" style="width: 500px; height: 300px; background-color: lightblue;"> <input type="button" name="b1" value="Click Here" onclick='first()'/> B. Ramamurthy CSE651 1/11/2019

Document Object Model (DOM) The Document Object Model (DOM) is a programming API for HTML and XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated. It is hierarchical. Here is the for the html table. B. Ramamurthy CSE651 1/11/2019

DOM for general HTML document table id div id button id form id/index B. Ramamurthy CSE651 1/11/2019

DOM nodes In the HTML DOM (Document Object Model), everything is a node: The document itself is a document node All HTML elements are element nodes All HTML attributes are attribute nodes Text inside HTML elements are text nodes Comments are comment nodes B. Ramamurthy CSE651 1/11/2019

DOM usage Using the DOM structure we can refer to the various elements of the html document using “OO” dot notation Example: add this line to first function in the ex4.js file document.write (“Hello everyone!”); Save and run the e4.html B. Ramamurthy CSE651 1/11/2019

DOM objects Many useful DOM objects are available; One thats of use to us is the Math object You can use most any math function: var x = Math.PI; // Returns PI var y = Math.sqrt(64); // Returns the square root of 64 B. Ramamurthy CSE651 1/11/2019

Lets do some computation Lets add a text box, do some computation in the javascript and return to the document Start a new exercise Save ex4.html as ex5.html, ex4,js as ex5.js Modify ex4.html to have a textbox element Change the button to Get Random Number Make sure to change script file linked to ex5.js We have also introduced the “form” tag, that is a very useful tag As shown in the code next B. Ramamurthy CSE651 1/11/2019

Ex5.html <script type="text/javascript" src="ex5.js"> </head> <body> <form> <div id="auto_panel" style="width: 500px; height: 300px; background-color: lightblue;"> <input type="button" name="b1" value="Get Random Number" onclick='myrand()'/> <br> <input type="text" name="randomNumber" value="0" onchange=''/> </div> </form> B. Ramamurthy CSE651 1/11/2019

Ex5.js var rnum; function myrand() { alert (" Button was clicked!"); rnum = Math.floor(Math.random()*100 ); // a number between 0-99 inclusive alert(rnum); document.forms[0].randomNumber.value = rnum; } B. Ramamurthy CSE651 1/11/2019

JS driven by Analytics Where do the analytics come in? Lets now make an application with html and js that is driven by one of our simplest statistical models: linear regression This is basically a template for any other application you may write. Html interface Javascript functions Analytics B. Ramamurthy CSE651 1/11/2019

Linear regression Application Lets plan the interface: y = a + bx We need input boxes for a, b and x and an output box for displaying the result in y A button to start the analytics (simple in this case) Like mentioned before this example is simply a template, the analytics could me more complex than this. This is an in-class exercise for you. B. Ramamurthy CSE651 1/11/2019

Summary We looked basic features of Javascript working with html input interface Any analytics module can be easily be made to power this workflow that we studied / practiced in this session Study the material/paper given in the reference for more information on javascript. B. Ramamurthy CSE651 1/11/2019

References Third Party JavaScript book DOM standard: http://www.w3.org/TR/1998/WD-DOM-19980720/introduction.html DOM: w3schools.com B. Ramamurthy CSE651 1/11/2019