Technical University of Sofia Faculty of Computer Systems and Control. Web Programming. Lecture 5 JavaScript part 2



Similar documents
Internet Technologies

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

The purpose of jquery is to make it much easier to use JavaScript on your website.

jquery Tutorial for Beginners: Nothing But the Goods

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Technical University of Sofia Faculty of Computer Systems and Control. Web Programming. Lecture 4 JavaScript

Intell-a-Keeper Reporting System Technical Programming Guide. Tracking your Bookings without going Nuts!

Web Development 1 A4 Project Description Web Architecture

Example. Represent this as XML

CS412 Interactive Lab Creating a Simple Web Form

Overview. In the beginning. Issues with Client Side Scripting What is JavaScript? Syntax and the Document Object Model Moving forward with JavaScript

Website Login Integration

2- Forms and JavaScript Course: Developing web- based applica<ons

MASTERTAG DEVELOPER GUIDE

Tutorial 6 Creating a Web Form. HTML and CSS 6 TH EDITION

JavaScript and Dreamweaver Examples

Working with forms in PHP

LAB MANUAL CS (22): Web Technology

Yandex.Widgets Quick start

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Major Subject

Hello World RESTful web service tutorial

Lab 5 Introduction to Java Scripts

JavaScript Basics & HTML DOM. Sang Shin Java Technology Architect Sun Microsystems, Inc. sang.shin@sun.com

Configuring iplanet 6.0 Web Server For SSL and non-ssl Redirect

XHTML BASICS. Institute of Finance Management CIT Department Herman Mandari

Website Implementation

Script Handbook for Interactive Scientific Website Building

Slightly more advanced JavaScript

Further web design: HTML forms

Implementing Specialized Data Capture Applications with InVision Development Tools (Part 2)

HTML Forms and CONTROLS

Tutorial: Using PHP, SOAP and WSDL Technology to access a public web service.

Client-side Web Engineering From HTML to AJAX

ANGULAR JS SOFTWARE ENGINEERING FOR WEB SERVICES HASAN FAIZAL K APRIL,2014

PLAYER DEVELOPER GUIDE

Web Development CSE2WD Final Examination June (a) Which organisation is primarily responsible for HTML, CSS and DOM standards?

Chapter 2: Interactive Web Applications

Building Web Applications with HTML5, CSS3, and Javascript: An Introduction to HTML5

Intro to jquery. Web Systems 02/17/2012

Dynamic Web-Enabled Data Collection

People Data and the Web Forms and CGI. HTML forms. A user interface to CGI applications

Client-side programming with JavaScript. Laura Farinetti Dipartimento di Automatica e Informatica Politecnico di Torino laura.farinetti@polito.

CIS 467/602-01: Data Visualization

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

<option> eggs </option> <option> cheese </option> </select> </p> </form>

Inserting the Form Field In Dreamweaver 4, open a new or existing page. From the Insert menu choose Form.

JavaScript Introduction

Viewing Form Results

Visualizing an OrientDB Graph Database with KeyLines

IMRG Peermap API Documentation V 5.0

Visualizing a Neo4j Graph Database with KeyLines

This matches a date in the MM/DD/YYYY format in the years The date must include leading zeros.

Making Web Application using Tizen Web UI Framework. Koeun Choi

Chapter 2 HTML Basics Key Concepts. Copyright 2013 Terry Ann Morris, Ed.D

Abusing HTML5. DEF CON 19 Ming Chow Lecturer, Department of Computer Science TuCs University Medford, MA

HTML Tables. IT 3203 Introduction to Web Development

Web Design Basics. Cindy Royal, Ph.D. Associate Professor Texas State University

Cross-Platform Tools

Web Programming Step by Step

Website Planning Checklist

JQUERY - EFFECTS. Showing and Hiding elements. Syntax. Example

«W3Schools Home Next Chapter» JavaScript is THE scripting language of the Web.

Contents. 2 Alfresco API Version 1.0

Web Building Blocks. Joseph Gilbert User Experience Web Developer University of Virginia Library

Introduction to XHTML. 2010, Robert K. Moniot 1

Forms, CGI Objectives. HTML forms. Form example. Form example...

Online Multimedia Winter semester 2015/16

the intro for RPG programmers Making mobile app development easier... of KrengelTech by Aaron Bartell

Portals and Hosted Files

How to code, test, and validate a web page

JavaScript: Arrays Pearson Education, Inc. All rights reserved.

Understanding Cross Site Scripting

Sample HP OO Web Application

CSE 154 LECTURE 18: THE DOCUMENT OBJECT MODEL (DOM); UNOBTRUSIVE JAVASCRIPT

Programming in HTML5 with JavaScript and CSS3

Blufusion.net. Easy AJAX Post with jquery and CodeIgniter. Home. php javascript jquery codeigniter web development.

ACCESSING THE PROGRESS OPENEDGE APPSERVER FROM PROGRESS ROLLBASE USING JSDO CODE

oncourse web design handbook Aristedes Maniatis Charlotte Tanner

Introduction to PhoneGap

Slide.Show Quick Start Guide

JAVASCRIPT AND COOKIES

Linklok URL TM V2.90

RESTful web applications with Apache Sling

Installation and Integration Manual TRANZILA Secure 5

CarTrawler AJAX Booking Engine Version: 5.10 Date: 01/10/13.

Transcription:

Technical University of Sofia Faculty of Computer Systems and Control Web Programming Lecture 5 JavaScript part 2

JAVASCRIPT AND FORMS 11/13/201 4 Assist. Prof. Antonia Tasheva 2

Page Title <!DOCTYPE html> <html> <head> <title>w3schools Demo</title> </head> <body> <p id="demo"></p> document.getelementbyid("demo").innerhtml = "The title of this document is: " + document.title; </body> </html> 11/13/2014 Assist. Prof. Antonia Tasheva 3

Disable a button <input type="button" id="btn01" value="ok"> <p>click the "Disable" button to disable the "OK" button:</p> <button onclick="disableelement()">disable</button> function disableelement() { document.getelementbyid("btn01").disabled = true; 11/13/2014 Assist. Prof. Antonia Tasheva 4

Disable/Enable a select function disable() { document.getelementbyid("myselect").disabled=true; function enable() { document.getelementbyid("myselect").disabled=false; <select id="myselect"> <option>apple</option> <option>pear</option> </select> <br><br> <input type="button" onclick="disable()" value="disable list"> <input type="button" onclick="enable()" value="enable list"> 11/13/2014 Assist. Prof. Antonia Tasheva 5

Select multiline list function changesize() { document.getelementbyid("myselect").size = 4; <form> <select id="myselect"> <option>apple</option> <option>banana</option> <option>orange</option> <option>melon</option> </select> <input type="button" onclick="changesize()" value="change size"> </form> 11/13/2014 Assist. Prof. Antonia Tasheva 6

Selected option function getoption() { var obj = document.getelementbyid("myselect"); document.getelementbyid("demo").innerhtml=obj.options[obj.selectedindex].text; Select your favorite fruit: <select id="myselect"> <option>apple</option> <option>orange</option> <option>pineapple</option> <option>banana</option> </select> <br><br> <input type="button" onclick="getoption()" value="click Me!"> <p id="demo"></p> 11/13/2014 Assist. Prof. Antonia Tasheva 7

Selected option (index) function getindex() { document.getelementbyid("demo").innerhtml = document.getelementbyid("myselect").selectedindex; Select your favorite fruit: <select id="myselect"> <option>apple</option> <option>orange</option> <option>pineapple</option> <option>banana</option> </select> <br><br> <input type="button" onclick="getindex() value="display the index /> <p id="demo"></p> 11/13/2014 Assist. Prof. Antonia Tasheva 8

Remove options function removeoption() { var x = document.getelementbyid("myselect"); x.remove(x.selectedindex); <form> <select id="myselect"> <option>apple</option> <option>pear</option> <option>banana</option> <option>orange</option> </select> <input type="button" onclick="removeoption()" value="remove the selected option"> </form> 11/13/2014 Assist. Prof. Antonia Tasheva 9

name <button id="btn1" name="subject" type="submit value="html">html</button> <p>click the "Try it" button to display the name of the "HTML" button:</p> <button onclick="myfunction()">try it</button> <p id="demo"></p> function myfunction() { var x = document.getelementbyid("btn1").name; document.getelementbyid("demo").innerhtml = x; 11/13/2014 Assist. Prof. Antonia Tasheva 10

type <button id="btn1" type="button">html</button> <p>click the "Try it" button to return the type of the "HTML" button:</p> <button onclick="myfunction()">try it</button> <p id="demo"></p> function myfunction() { var x = document.getelementbyid("btn1").type; document.getelementbyid("demo").innerhtml = x; 11/13/2014 Assist. Prof. Antonia Tasheva 11

value <form id="frm1" action="form_action.asp"> <button id="btn1" name="subject" type="submit" value="fav_html">html</button> <button id="btn2" name="subject" type="submit" value="fav_css">css</button> </form> <p>click the "Try it" button to return the value of the "HTML" button:</p> <button onclick="myfunction()">try it</button> <p id="demo"></p> function myfunction() { var x = document.getelementbyid("btn1").value; document.getelementbyid("demo").innerhtml = x; 11/13/2014 Assist. Prof. Antonia Tasheva 12

text displayed on a button <form id="frm1" action="form_action.asp"> <button id="btn1" name="subject" type="submit" value="fav_html">html</button> <button id="btn2" name="subject" type="submit" value="fav_css">css</button> </form> <p>click the "Try it" button to return the text on the "HTML" button:</p> <button onclick="myfunction()">try it</button> <p id="demo"></p> function myfunction() { var x = document.getelementbyid("btn1").innerhtml; document.getelementbyid("demo").innerhtml = x; 11/13/2014 Assist. Prof. Antonia Tasheva 13

Reset a Form <p>enter names in the fields below, then click "Reset" to reset the form.</p> <form id="frm1"> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br><br> <input type="button" onclick="myfunction()" value="reset"> </form> function myfunction() { document.getelementbyid("frm1").reset(); 11/13/2014 Assist. Prof. Antonia Tasheva 14

Find elements in a form <form id="frm1" action="form_action.asp"> First name: <input type="text" name="fname" value="donald"><br> Last name: <input type="text" name="lname" value="duck"><br><br> <input type="submit" value="submit"> </form> <p>click "Try it" to display the value of each element in the form.</p> <button onclick="myfunction()">try it</button> <p id="demo"></p> function myfunction() { var x = document.getelementbyid("frm1"); var text = ""; var i; for (i = 0; i < x.length ;i++) { text += x.elements[i].value + "<br>"; document.getelementbyid("demo").innerhtml = text; 11/13/2014 Assist. Prof. Antonia Tasheva 15

Browser Info <p>what is the name(s) of your browser?</p> <button onclick="myfunction()">try it</button> <p id="demo"></p> function myfunction() { document.getelementbyid("demo").innerhtml = "Name is " + navigator.appname + "<br>code name is " + navigator.appcodename; 11/13/2014 Assist. Prof. Antonia Tasheva 16

jquery 11/13/201 4 Assist. Prof. Antonia Tasheva 17

What is jquery An open source JavaScript library that simplifies the interaction between HTML and JavaScript. Created by John Resig in 2005, released in January of 2006. jquery is the most popular JavaScript framework on the Internet today. Built in an attempt to simplify the existing DOM APIs and abstract away cross-browser issues. It uses CSS selectors to access and manipulate HTML elements (DOM Objects) on a web page. jquery also provides a companion UI (user interface) framework and numerous other plug-ins. 11/13/2014 Assist. Prof. Antonia Tasheva 18

What Is The DOM? Long story short, the DOM is your html document code. From the <!DOCTYPE> to the </html> The DOM is loaded top to bottom, so include your scripts at the bottom of the page for best performance. The DOM is "ready" when everything on the page has loaded. Stylesheets JavaScripts Images

How to include jquery Simply add the link or add the file to your site and address it locally In order to use jquery you need to load it. You can include it locally on your own server: <script src="/js/jquery.js"> Or use one of the CDN's made available: ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js CDN's are Gzipped and minified <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> 11/13/2014 Assist. Prof. Antonia Tasheva 20

Ready Event In order to make sure that jquery can find the element you asked it for, your browser needs to have loaded it (the DOM needs to be ready). Q. How can I be sure my code runs at DOM ready? A. Wrap all your jquery code with the document ready function: $(document).ready(function(){ // insert sweet, sweet jquery code here );

JavaScript vs jquery Example 1 - Hide an element with id "textbox //javascript document.getelementbyid('textbox').style.display = "none"; //jquery $('#textbox').hide(); Example 2 - Create a <h1> tag with "my text //javascript var h1 = document.createelement("h1"); h1.innerhtml = "my text"; document.getelementsbytagname('body')[0].appendchild(h1); //jquery $('body').append( $("<h1/>").html("my text") ; 11/13/2014 Assist. Prof. Antonia Tasheva 22

Finding things - selectors TagName document.getelementsbytagname("tagname"); $("tagname") - $("div"), $("p"), $("div"),... Tag ID document.getelementbyid("id"); $("#id") - $("#name"), $("#address") Tag Class document.getelementsbyclassname("classname"); $(".classname") - $(".comment"), $(".code") To select all elements - $("*") 11/13/2014 Assist. Prof. Antonia Tasheva 23

Example <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> function myfunction() { $("#h01").attr("style", "color:red").html("hello jquery") $(document).ready(myfunction); </head> <body> <h1 id="h01"></h1> </body> </html> 11/13/2014 Assist. Prof. Antonia Tasheva 24

More examples Site with jquery http://ejohn.org/apps/workshop/intro/#11 11/13/2014 Assist. Prof. Antonia Tasheva 25

Thank you for your attention! 11/13/2014 Assist. Prof. Antonia Tasheva 26