35
Applied Component I Unit II Introduction of java-script Java-script in web browser Forms and form elements String manipulation

Applied component i unit 2

Embed Size (px)

Citation preview

Page 1: Applied component i unit 2

Applied Component I

Unit II•Introduction of java-script•Java-script in web browser•Forms and form elements•String manipulation

Page 2: Applied component i unit 2

1.Introduction to java-script

Page 3: Applied component i unit 2

1.Introduction to java-script

• Java-script is a powerful client level scripting languages

• Java-script is not java• Java-script is a best supported scripting language

for many browsers• It can be written inside <script> tag or in file with

extension .js• JavaScript is usually embedded directly into

HTML pages• JavaScript is Case Sensitive

Page 4: Applied component i unit 2

How to write java-script<html><head><script language="javascript">function call(){

alert("do u have any problem! hold on");alert("lets start learning java-script");

}</script></head><body><input type="button" value="simple button" onclick="call()"></body></html>

Page 5: Applied component i unit 2

2.Client side java script

Page 6: Applied component i unit 2

string objects• The main purpose of String Object in

JavaScript is for storing text.

math objects• The main purpose of math object in javaScript is

to perform math operation like sin,cos,tan operations

Page 7: Applied component i unit 2

array object• It is a array handler in javascript

Date object• It gives access to date method, for displaying and

setting date

Page 8: Applied component i unit 2

Java script in web browser

Page 9: Applied component i unit 2

window Object• The window object represents the browser’s

frame or window, in which your web page is contained

• via the properties of the window object you can find out what browser is running, the pages the user has visited, the size of the browser window, the size of the user’s screen

• The window object is a global object, which means you don’t need to use its name to access its properties and methods– window.alert(“Hello class!”);– Window.defaultStatus = “see your status bar”

Page 10: Applied component i unit 2

history Object

• The history object keeps track of each page that the user visits

• This list of pages is commonly called the history stack for the browser

• It enables the user to click the browser’s Back and Forward buttons to revisit pages

• the history object has the back() and forward() methods.

• The history object also has the go() method.

Page 11: Applied component i unit 2

• history.back();– one page back

• history.forward();– One page forward

• history.go(-3);– three page back

• history.go(3);– Three page forward

Page 12: Applied component i unit 2

location Object

• The location object contains lots of potentially useful information about the current page’s location.– it contain the URL (Uniform Resource Locator) for

the page– server hosting– port number of the server connection– the protocol used

Page 13: Applied component i unit 2

Navigate using location object

• You can navigate to another page in two ways– location object’s href property– location object’s replace() method

• replace() method removes the current page from the history stack and replaces it with the new page

• href property simply adds the new page to the top of the history stack

Page 14: Applied component i unit 2

Navigator object

• navigator object contains lots of information about the browser and the operating system in which it’s running.

Page 15: Applied component i unit 2

document Object—The Page Itself

• The document object has a number of properties associated with it, which are also arrays. The main ones are the forms, images, and links arrays.– document.bgColor=“green”;– document.images.length• This will return how many image are on web page

– document.images[“image1”].• It is the array of images of name “image1”

Page 16: Applied component i unit 2

Events and event handling

• Basic html event– onclick=”alert(‘You Clicked?’)”– Onload=“”– Onunload=“”

• window.document.links["anc1"].onclick = linkclick;– Special event handler has to be load after full html

page is cached

Page 17: Applied component i unit 2

3.Forms and form elements

Page 18: Applied component i unit 2

Forms and form elements

• document.forms.length;– Returns count of form tags on document

• Document.form1.button1.value=“hello”;– Changes the value of button1

• document.form1.txt1.focus();– Takes focus on txt1(textbox)

• document.form1.txt1.select();– Selects all text in txt1(textbox)

Page 19: Applied component i unit 2

Windows and frames

• var newWindow = window.open(myURL,”myWindow”,”width=125,height=150,resizable”);

• newWindow.resizeTo(350,200);– resize your window to 350 pixels wide by 200

pixels

• newWindow.moveTo(100,400);– move it so it’s 100 pixels from the left of the

screen and 400 pixels from the top

Page 20: Applied component i unit 2

• newWindow.resizeBy(100,200);– increase the size of newWindow by 100 pixels

horizontally and 200 pixels vertically

• newWindow.moveBy(20,50);– move the newWindow by 20 pixels horizontally

and 50 pixels vertically

Page 21: Applied component i unit 2

Dynamic html

• DHTML is the manipulation of an HTML document after it is loaded into the browser, and the most common way to manipulate the document is by changing the way HTML elements look

Page 22: Applied component i unit 2

Accessing Elements

• The Document Object Model (DOM) holds the ability you need to find and access HTML elements; the DOM is a hierarchical tree, and you can certainly climb it, inspect every branch and leaf, and find what you’re looking for

• document.getElementById(“divAdvert”)

Page 23: Applied component i unit 2

Changing Appearances

• document.getElementById(“divAdvert”).style.color = “red”

Page 24: Applied component i unit 2

Positioning and Moving Content

• document.getElementById("div1").style.left = "100px";

• document.getElementById("div1").style.top = "200px";

Page 25: Applied component i unit 2

4.String manipulation

Page 26: Applied component i unit 2

Additional String Methods

• split() Method– var myString = “A,B,C”;– var myTextArray = myString.split(‘,’);

• replace() Method– var myString = “The event will be in May, the 21st

of June”;– myCleanedUpString =

myString.replace(“May”,”June”);

Page 27: Applied component i unit 2

• search() Method– var myString = “Beginning JavaScript, Beginning

Java, Professional JavaScript”;– alert(myString.search(“Java”));

• alert box that occurs will show the value 10, which is the character position of the J in the first occurrence of Java

Page 28: Applied component i unit 2

• match() Method– var myString = “1997, 1998, 1999, 2000, 2000,

2001, 2002”;– myMatchArray = myString.match(“2000”);– alert(myMatchArray.length);

• instead of returning the position at which a match was found, it returns an array.

Page 29: Applied component i unit 2

Regular expression

• A regular expression is an object that describes a pattern of characters.

• Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text.

• syntax– var txt=/pattern/modifiers;– var txt=new RegExp(pattern,modifiers);

Page 30: Applied component i unit 2

modifiers

Page 31: Applied component i unit 2
Page 32: Applied component i unit 2
Page 33: Applied component i unit 2
Page 34: Applied component i unit 2
Page 35: Applied component i unit 2