"> ">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I.

Similar presentations


Presentation on theme: "Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I."— Presentation transcript:

1 Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I

2 2 Introduction JavaScript is a __________ language developed by __________ and supported by all major __________. A scripting language is a lightweight _____________ language. JavaScript code can be inserted into an _______ document. JavaScript can make web pages more ___________ since it uses ___________ and can respond to _______, like a mouse click. JavaScript can also be used on the client to _________ form data before it is sent to the server.

3 3 How To … Inserting JavaScript code into an HTML document requires the __________ tag. <!-- hide from older browsers document.write(" Hello World! "); // stop hiding -->

4 4 Where To …Where To … I Scripts in the ______ section will execute while the page loads (see previous slide for an example). Scripts in the ______ section will be executed when called or when an event is triggered. function message() { window.alert("This alert box was called with the onload event"); }

5 5 Where To … II You can place JavaScript code in an _________ file with a ____ extension. The actual script is in an external script file called "myjavascript.js".

6 6 Variables A variable is a “__________” for information you want to store. Variable names are ______ sensitive and must begin with a letter or ___________. This is how you declare a variable called strname: var strname = “Joe” ; A variable declared inside a function is ______ and is destroyed when the function is exited. A variable declared outside a function is ________ and is destroyed when the page is closed. See the example.example

7 7 Window ObjectWindow Object I Alert box Alert window.alert("Hello World!") Confirm box Confirm var name = window.confirm("Press a button"); if (name == true) { document.write("You pressed OK"); } else { document.write("You pressed Cancel"); }

8 8 Window ObjectWindow Object II Prompt box Prompt var name = prompt("Please enter your name",“Right here"); if (name != null && name != "") { document.write("Hello " + name); } Function to open two new windowsopen function openwindow() { window.open("http://www.microsoft.com"); window.open("http://www.w3schools.com"); } Sending to a new locationlocation location=http://www.w3schools.com/;

9 9 OperatorsOperators I Arithmetic operators: _______________________ 5 * (4 – 2) / 2 + 3 = ______ 17 % 3 = ______ (5 with a remainder of 2) 14++ = _____ Assignment operators x = 5 (x is __________ the value 5) x = y (x is assigned the value that is stored in y) x+=5  x=x+5, x*=y  x=x*y, and so on Comparison operators == (is equal to), != (is NOT equal to), > (______ than), …

10 10 OperatorsOperators II Logical operators && means ______, || means ______, ! means _______ String operator + text1 = “Hello”; text2 = “world!”; text3 = text1 + “ ” + text2; document.write (text3); (will print “_____________”)

11 11 ConditionalConditional I if statement var todaysDate = new Date() var time = todaysDate.getHours() if (time < 10) { document.write(" Good morning "); } if…_____ statement if (time < 10) { document.write(" Good morning "); } else { document.write(" Good day "); }

12 12 ConditionalConditional II _________ statement var d = new Date() theDay=d.getDay() switch (theDay) { case 5: document.write("Finally Friday"); break; case 6: document.write("Super Saturday"); break; case 0: document.write("Sleepy Sunday"); break; default: document.write("I'm really looking forward to this weekend!"); }


Download ppt "Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I."

Similar presentations


Ads by Google