JavaScript CSCI 201 Principles of Software Development

Similar documents
JSP CSCI 201 Principles of Software Development

Consider the following file A_Q1.html.

blink.html 1/1 lectures/6/src/ form.html 1/1 lectures/6/src/

Assessment: Course Four Column SPRING / SUMMER 2016

Javascript Lecture 23

Hyperlinks, Tables, Forms and Frameworks

Spring 2014 Interim. HTML forms

Form Processing in PHP

JavaScript s role on the Web

Chapter4: HTML Table and Script page, HTML5 new forms. Asst. Prof. Dr. Supakit Nootyaskool Information Technology, KMITL

JAVASCRIPT HTML DOM. The HTML DOM Tree of Objects. JavaScript HTML DOM 1/14

5.5 FORM form ex28.html <html> <head>

<form>. input elements. </form>

HTML Forms. By Jaroslav Mohapl

Introduction to using HTML to design webpages

Lecture : 3. Practical : 2. Course Credit. Tutorial : 0. Total : 5. Course Learning Outcomes

Q1. What is JavaScript?

By completing this practical, the students will learn how to accomplish the following tasks:

Manual Html A Href Onclick Submit Button

Manual Html A Href Onclick Submit Form

Creating Forms. Speaker: Ray Ryon

PIC 40A. Review for the Final. Copyright 2011 Jukka Virtanen UCLA 1 06/05/15

HTML MIS Konstantin Bauman. Department of MIS Fox School of Business Temple University

AIM. 10 September

Web Development and HTML. Shan-Hung Wu CS, NTHU

HTML Tables and Forms. Outline. Review. Review. Example Demo/ Walkthrough. CS 418/518 Web Programming Spring Tables to Display Data"

By the end of this section of the practical, the students should be able to:

HTML. HTML Evolution

Notes General. IS 651: Distributed Systems 1

Web Designing HTML5 NOTES

Introduction to DHTML

EXPERIMENT OBJECTIVE:

COM1004 Web and Internet Technology

Practice problems. 1 Draw the output for the following code. 2. Draw the output for the following code.

CSS Scripting and Computer Environment - Lecture 09

UNIT-VI CREATING AND USING FORMS

CPSC 481: CREATIVE INQUIRY TO WSBF

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II

Lecture (03) from static HTML to

CSC 337. JavaScript Object Notation (JSON) Rick Mercer

SQL CSCI 201 Principles of Software Development

LING 408/508: Programming for Linguists. Lecture 13 October 14 th

Form Overview. Form Processing. The Form Element. CMPT 165: Form Basics

HTML and CSS MIS Konstantin Bauman. Department of MIS Fox School of Business Temple University

Programmazione Web a.a. 2017/2018 HTML5

Week 13 Thursday (with Page 5 corrections)

Abstract Classes Interfaces CSCI 201 Principles of Software Development

Abstract Classes Interfaces CSCI 201 Principles of Software Development

JavaScript Introduction

The Hypertext Markup Language (HTML) Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013

HTML, CSS, JavaScript

CMT111-01/M1: HTML & Dreamweaver. Creating an HTML Document

CSC 405 Computer Security. Web Security

CIW 1D CIW JavaScript Specialist.

Client Side JavaScript and AJAX

Web Programming HTML CSS JavaScript Step by step Exercises Hans-Petter Halvorsen

Outline. Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages

JavaScript I.b CSCI311

COMP1000 Mid-Session Test 2017s1

HTML Form. Kanida Sinmai

EXPRESSIONS IN ANGULARJS

Last &me: Javascript (forms and func&ons)

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

LAB MANUAL SUBJECT: WEB TECHNOLOGY CLASS : T.E (COMPUTER) SEMESTER: VI

INTRODUCTION TO JAVASCRIPT

HTML forms and the dynamic web

UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2016 EXAMINATIONS. CSC309H1 S Programming on the Web Instructor: Ahmed Shah Mashiyat

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains 2 components

Input and Validation. Mendel Rosenblum. CS142 Lecture Notes - Input

Exam Format: Multiple Choice, True/False, Short Answer (3 points each 75 points total) Write-the-page (25 points)

Session 5. Web Page Generation. Reading & Reference

1$ 5 ! $ 6 4 * Source: 0 "!*! 0! * 8 97 ?!$ 5 0 *! 4! $ 0 : * ' () 7;7 7<7

CS/COE 1520

Chapter 6 How to script the DOM with JavaScript

ajax1.html 1/2 lectures/9/src/ajax/ ajax1.html 2/2 lectures/9/src/ajax/

This is CS50. Harvard College Fall Quiz 1 Answer Key

First Simple Interactive JSP example

Multimedia im Netz (Online Multimedia) Wintersemester 2014/15. Übung 11 (Hauptfach)

Web Programming/Scripting: JavaScript

Mouse-over Effects. Text based buttons

Databases CSCI 201 Principles of Software Development

External HTML E-form Guide

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2018)

INTRODUCTION TO CGI PROGRAMMING By Jumail Bin Taliba, GMM, FSKSM, UTM INTRODUCTION

Comp-206 : Introduction to Software Systems Lecture 23. Alexandre Denault Computer Science McGill University Fall 2006

CIS 228 (Spring, 2012) Final, 5/17/12

Place User-Defined Functions in the HEAD Section

Advantages: simple, quick to get started, perfect for simple forms, don t need to know how form model objects work

Jquery Ajax Json Php Mysql Data Entry Example

Exploring Computer Science Web Final - Website

Session 6. JavaScript Part 1. Reading

CMPS 401 Survey of Programming Languages

PHP with data handling

MPT Web Design. Week 1: Introduction to HTML and Web Design

JavaScript!= Java. Intro to JavaScript. What is JavaScript? Intro to JavaScript 4/17/2013 INTRODUCTION TO WEB DEVELOPMENT AND HTML

JavaScript Introduction

Forms, Form Events, and Validation. Bok, Jong Soon

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 13: Intro to JavaScript - Spring 2011

1 Form Basics CSC309

University of Washington, CSE 154 Section 10: Practice Final Exam Problems

Transcription:

JavaScript CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu

Outline JavaScript Program USC CSCI 201L

JavaScript JavaScript is a front-end interpreted language that gives the programmer more control and functionality than HTML and CSS JavaScript can be included In an attribute of a tag In a <script> tag In an external JavaScript file (typically named with a.js extension) JavaScript is officially known as ECMAScript ECMAScript was first standardized in 1997 The current version of ECMAScript is 5.1, corresponding to JavaScript version 1.8.5, released in 2011 Is this image correct for JavaScript? USC CSCI 201L 3/12

Front-End or Back-End Is JavaScript a front-end or back-end language? Traditionally it has been a front-end language, but there has been an increase in server-side JavaScript recently (such as node.js) Be careful if you are using client-side JavaScript because users can disable JavaScript in their browsers Form validation and other critical items should be done on the server-side (and possibly on the client-side as well if you want) USC CSCI 201L 4/12

Client-Side JavaScript Client-side JavaScript can be disabled in browsers Form validation and other critical items should be done on the server-side (and possibly on the client-side as well if you want) USC CSCI 201L 5/12

My First JavaScript 1 <!DOCTYPE html> 2 <html> 3 <body> 4 <h1>my First JavaScript</h1> 5 <button type="button" 6 onclick="document.getelementbyid('demo').innerhtml = Date()"> 7 Click me to display Date and Time. 8 </button> 9 <p id="demo"></p> 10 </body> 11 </html> USC CSCI 201L 6/12

My Second JavaScript 1 <!DOCTYPE html> 2 <html> 3 <body> 4 <h1>csci 201 JavaScript</h1> 5 <p>click the button to see some hidden text.</p> 6 <p id="hello" style="display:none">hello CSCI 201!</p> 7 <button type="button" onclick="document.getelementbyid('hello').style.display='block'"> 8 Click Me! 9 </button> 10 </body> 11 </html> USC CSCI 201L 7/12

JavaScript Functions 1 JavaScript functions belong in the <head> tag or in an external JavaScript file 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>sample Form</title> 5 <script> 6 function validate() { 7 var haserror = false; 8 document.getelementbyid("ferror").innerhtml = ""; 9 document.getelementbyid("lerror").innerhtml = ""; 10 if (document.myform.fname.value.length <= 0) { 11 document.getelementbyid("ferror").innerhtml = "<font color=\"red\">please fill in first name.</font>"; 12 haserror = true; 13 } 14 if (document.myform.lname.value.length <= 0) { 15 document.getelementbyid("lerror").innerhtml = "<font color=\"red\">please fill in last name.</font>"; 16 haserror = true; 17 } 18 return!haserror; 19 } 20 </script> 21 </head> 22 <body> 23 <form name="myform" method="get" action="form.jsp" onsubmit="return validate();"> 24 First Name <input type="text" name="fname" /><span id="ferror"></span><br /> 25 Last Name <input type="text" name="lname" /><span id="lerror"></span><br /> 26 <input type="submit" name="submit" value="submit" /> 27 </form> 28 </body> 29 </html> USC CSCI 201L 8/12

JavaScript Functions 2 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>sample Form</title> 5 <script> 6 function sort() { 7 var arr = new Array(); 8 arr[0] = Number(document.myform.num1.value); 9 arr[1] = Number(document.myform.num2.value); 10 arr[2] = Number(document.myform.num3.value); 11 arr[3] = Number(document.myform.num4.value); 12 arr[4] = Number(document.myform.num5.value); 13 for (var i=0; i < arr.length; i++) { 14 for (var j=i+1; j < arr.length; j++) { 15 if (arr[i] > arr[j]) { 16 var temp = arr[i]; 17 arr[i] = arr[j]; 18 arr[j] = temp; 19 } 20 } 21 } 22 var sortedarray = ""; 23 for (var i=0; i < arr.length; i++) { 24 sortedarray += arr[i]; 25 if (i!= arr.length - 1) { 26 sortedarray += ","; 27 } 28 } 29 document.getelementbyid("sortednumbers").innerhtml = sortedarray; 30 return false; 31 } 32 </script> 33 </head> 34 <body> 35 <form name="myform" method="get" onsubmit="return sort();"> 36 Number 1 <input type="text" name="num1" /><br /> 37 Number 2 <input type="text" name="num2" /><br /> 38 Number 3 <input type="text" name="num3" /><br /> 39 Number 4 <input type="text" name="num4" /><br /> 40 Number 5 <input type="text" name="num5" /><br /> 41 <input type="submit" name="submit" value="submit" /> 42 </form> 43 <div id="sortednumbers"></div> 44 </body> 45 </html> USC CSCI 201L 9/12

More JavaScript For more information on JavaScript Go to http://www.w3schools.com/js/ View the source of any web page to see the JavaScript that was used on that page Go through one of many tutorials you find online 10/12

Outline JavaScript Program USC CSCI 201L

Program Write a program that validates the form based on rules for different types of fields Email should have an @ with at least one. After Passwords should be at least 8 characters long with at least 1 number Birthday must be a date in the past New Student must have one option selected College must have a value Favorite color must have a value other than Black Terms and Conditions must be checked Do not allow the form to be submitted otherwise. Put a message next to each field that is not formatted correctly Program USC CSCI 201L 12/12