Download presentation
Presentation is loading. Please wait.
Published byGeorgina Morgan Modified over 9 years ago
1
CIS 375—Web App Dev II JavaScript III
2
2 The String Object A JS String is an object with properties and _________. For more info on JavaScript click here. http://www.pageresource.com/ http://hotwired.lycos.com/webmonkey/javascript/tutorials/tutorial1.ht ml http://hotwired.lycos.com/webmonkey/javascript/tutorials/tutorial1.ht ml http://wdvl.internet.com/Authoring/JavaScript/Tutorial/ Examples: var phrase = "W3Schools is great!“ // creates a String document.write(phrase.length) // displays “19” var pos = phrase.indexOf("School") // stores “2” document.write(phrase.substr(2,6)) // displays “School”
3
3 The Array Object Example var famName = new Array(6) // array w/ 6 items famName[0] = "Jan Egil" famName[1] = "Tove" famName[2] = "Hege" famName[3] = "Stale" famName[4] = "Kai Jim" famName[5] = "Borge" for (i=0; i<6; i++){ document.write(famName[i] + " ") }
4
4 The Date Object Example var today = new Date() // create a date object var weekday = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday", "Friday","Saturday") // create an array var monthname = new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug", "Sep","Oct","Nov","Dec") // create an array // display day of week document.write(weekday[today.getDay()] + “ ") // display date document.write(today.getDate() + ". ") // display month and full year document.write(monthname[today.getMonth()] + " ") document.write(today.getFullYear())
5
5 The Math Object Example: // get a random number between 0 and 10 randomNum = Math.random()*10 /* round it up to an integer so that the result is a random integer from 1 to 10 */ document.write(Math.ceil(randomNum))
6
6 The Window Object I Example of a prompt box: var name = prompt("Please enter your name","") if (name != null && name != ""){ document.write("Hello " + name) } Load a page in the current location: window.location="http://www.w3schools.com/“ Print a page: window.print() Detect a client’s browser: document.write("You are browsing this site with: "+ navigator.appName)
7
7 The Window Object II Opening two windows on a button click: function openwindow(){ window.open("http://www.microsoft.com/") window.open("http://www.w3schools.com/") }
8
8 The Frame Object Breaking out of a frame: function breakout(){ if (window.top != window.self) { window.top.location="tryjs_breakout.htm" } To break out of the frame:
9
9 The Form Object I Validating a form entry: function validate(){ x=document.myForm at=x.myEmail.value.indexOf("@") if (at == -1){ alert("Not a valid e-mail") return false } <form name="myForm" action="tryjs_submitpa ge.htm" onsubmit="return validate()"> Enter your E-mail address:
10
10 The Form Object II Setting Focus function setfocus(){ document.forms[0]. field.focus() }
11
11 The Form Object III Displaying form field selections function check(browser){ document.forms[0]. answer.value = browser } Which browser is your favorite <input type = "radio" name = "browser" onclick = "check(this.value)" value = "Explorer"> MS Internet Explorer <input type = "radio“ name = "browser" onclick = "check(this.value)" value = "Netscape"> Netscape Navigator
12
12 The Browser Object Detecting the client’s browser document.write("BROWSER: ") document.write(navigator.appName + " ") document.write("BROWSERVERSION: ") document.write(navigator.appVersion + " ") document.write("CODE: ") document.write(navigator.appCodeName + " ") document.write("PLATFORM: ") document.write(navigator.platform + " ") document.write("REFERRER: ") document.write(document.referrer + " ")
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.