26-08-2014, 04:54 PM
JAVA SCRIPT SEMINAR REPORT
JAVA SCRIPT.docx (Size: 32.33 KB / Downloads: 11)
INTRODUCTION
JavaScript Origins
• JavaScript was released by Netscape and Sun Microsystems in 1995.
• However, JavaScript is not the same thing as Java.
What is JavaScript
• It is a programming language.
• It is an interpreted language.
• It is object-based programming.
• It is widely used and supported
• It is accessible to the beginner.
Uses of JavaScript
• Use it to add multimedia elements
With JavaScript you can show, hide, change, resize images, and create image rollovers. You can create scrolling text across the status
bar.
• Create pages dynamically
Based on the user's choices, the date, or other external data, JavaScript can produce pages that are customized to the user.
• Interact with the user
It can do some processing of forms and can validate user input when the user submits the form
Writing JavaScript
JavaScript code is typically embedded in the HTML, to be interpreted and run by the client's browser. Here are some tips to remember when writing JavaScript commands.
• JavaScript code is case sensitive
• White space between words and tabs are ignored
• Line breaks are ignored except within a statement
• JavaScript statements end with a semi- colon
SCRIPT Example
• Open "script_tag.html" in a browser.
• View the Source
• Put the cursor after <! – Enter code below -> and enter the following:
<SCRIPT language = "JavaScript">
alert("Welcome to the script tag test page.")
</SCRIPT>
• Save the changes by choosing Save from the File menu.
• Then Refresh the browser by clicking the Refresh or Reload button
PROGRAMMING BASICS
Programmers use variables to store values. A variable can hold several types of data. In JavaScript you don't have to declare a variable's data type before using it. Any variable can hold any JavaScript data type, including:
• String data
• Numbers
• Boolean values (T/F)
Variable Names
There are rules and conventions in naming variables in any programming language. It is good practice to use descriptive names for variables. The following are the JavaScript rules:
• The variable name must start with a letter or an underscore.
firstName or _myName
• You can use numbers in a variable name, but not as the first character.
name01 or tuition$
• You can't use space to separate characters.
userName not user Name
• Capitalize the first letter of every word except the first
• salesTax or userFirstName
User-Defined Functions
With user-defined functions, you can name a block of code and call it when you need it. You define a function in the HEAD section of a web page. It is defined with the function keyword, followed by the function name and any arguments.
function functionName(argument)
{
statements
OBJECTS
JavaScript supports programming with objects. Objects are a way of organizing the variables. The different screen elements such as Web pages, forms, text boxes, images, and buttons are treated as objects.
Properties and Methods
Every object has its own properties and methods.
• Properties define the characteristics of an object.
Examples: color, length, name, height, width
• Methods are the actions that the object can perform or that can be performed on the object.
Examples: alert, confirm, write, open, close
Naming Objects
• Objects are organized in a hierarchy. To refer to an object use :
objectName
• To refer to a property of an object use:
objectName.propertyName
• To refer to a method of an object use:
objectName.methodName()
Built-In Objects
Some of the built-in language objects of JavaScript offer more advanced operations such as:
• Math – provides for math calculations
• Date – provides date and time information
• String – provides for string manipulation
Math Object
The Math object provides methods for many mathematical calculations, including: abs(), log(), pow(), random(), round(), sqrt()
Format: Math.method(#)
DOCUMENT OBJECT
The Document object represents the Web page that is loaded in the browser window, and the content displayed on that page, including text and form elements.
Document Methods
You can use the methods of the document object to work on a Web page.Here are the most common document methods:
• write() - write a string to the Web page
• open() - opens a new document
• close() - closes the document
Document Example
• Keep the "userdefined.html" file open
• Put the cursor after the String example and enter:
document.write(myNum)
document.write(theYear)
document.write(printString)
document.write(numChars)
</SCRIPT>
• Save the changes and Refresh the page
Formatting What is Written
You will notice that the results of all four variable are printed on one line and without any spaces between the results. You can avoid this by including some formatting in your "document.write" statement.
Document Formatting Example
• Open "write.html" and View the Source
• Put the cursor after "<! – enter function ?" and enter:
<SCRIPT language="JavaScript">
function newPage() {
var userName = prompt("Please enter your name:", "")
OBJECTS AND EVENTS
Events
The objects in a Web pages are organized in a hierarchy. All objects have properties and methods. In addition, some objects also have "events". Events are things that happen, usually user actions, that are associated with an object. The "event handler" is a command that is used to specify actions in response to an event. Below are some of the most common events:
• onLoad - occurs when a page loads in a browser
• onUnload - occurs just before the user exits a page
• onMouseOver - occurs when you point to an object
• onMouseOut - occurs when you point away from an object
• onSubmit - occurs when you submit a form
• onClick - occurs when an object is clicked
Events and Objects
Events are things that happen, actions, that are associated with an object.
Below are some common events and the object they are associaated with:
Event Object
onLoad Body
onUnload Body
onMouseOver Link, Button
onMouseOut Link, Button
onSubmit Form
onClick Button, Checkbox, Submit,
Reset, Link