|
|||||||||||
![]() ![]() |
|
||||||||||
|
Gateway Education and Welfare Society (Regd.), Reg. No. DIC/DRA/1218 of 2002-- |
|||||||||||
|
|
What is JavaScript?JavaScript is the Netscape-developed object scripting language used in millions of web pages and server applications worldwide. Netscape's JavaScript is a superset of the ECMA-262 Edition 3 (ECMA Script) standard scripting language, with only mild differences from the published standard. Contrary to popular misconception, JavaScript is not "Interpretive Java". In a nutshell, JavaScript is a dynamic scripting language supporting prototype based object construction. The basic syntax is intentionally similar to both Java and C++ to reduce the number of new concepts required to learn the language. Language constructs, such as if statements, for and while loops, and switch and try ... catch blocks function the same as in these languages (or nearly so.) JavaScript can function as both a procedural and an object oriented language. Objects are created programmatically in JavaScript, by attaching methods and properties to otherwise empty objects at run time, as opposed to the syntactic class definitions common in compiled languages like C++ and Java. Once an object has been constructed it can be used as a blueprint (or prototype) for creating similar objects. JavaScript's dynamic capabilities include runtime object construction,
variable parameter lists, function variables, dynamic script creation (via
Intrinsic objects are For a more in depth discussion of JavaScript programming follow the JavaScript resources links below. What JavaScript implementations are available?mozilla.org hosts two JavaScript implementations. The first ever JavaScript was created by Brendan Each at Netscape, and has since been updated (in JavaScript 1.5) to conform to ECMA-262 Edition 3. This engine, code named Spider Monkey, is implemented in C. The Rhino engine, created primarily by Norris Boyd (also at Netscape) is a JavaScript implementation in Java. Like Spider Monkey, Rhino is ECMA-262 Edition 3 compliant. Each mozilla.org JavaScript engine exposes a public API applications can call on for JavaScript support. By far, the most common host environment for JavaScript is web browsers. Web browsers typically use the public API to create 'host objects' responsible for reflecting the DOM into JavaScript. Another common application for JavaScript is as a (web) server side scripting language. A JavaScript web server would expose host objects representing a HTTP request and response objects, which could then be manipulated by a JavaScript program to dynamically generate web pages. For more information on embedding JavaScript in your own applications, follow either the Spider Monkey or Rhino links below, or visit us on the nets cape .public .maxilla. sang newsgroup Java Script is used in millions of Web pages to add functionality, validate forms, detect browsers, and much more. JavaScript is easy to learn! You will enjoy it! JavaScript is a small, lightweight, object-oriented, cross-platform scripting language. For a brief introduction, read About JavaScript. For information about using JavaScript in browsers, please see DOM and DHTML topics. The Gecko DOM Reference describes the host objects available in Gecko-based browsers
Basic java script example <html> <body> <script type="text/java script"><html> <script type="text/java script"> Document . write("<h1>This is a header</h1>"); </script> </body> </html>
JavaScript Statements, Comments and Blocks
<html> <body> <script type="text/java script"> Document .write("<h1>This is a header</h1>"); Document . write("<p>This is a paragraph</p>"); Document . write("<p>This is another paragraph</p>"); </script> </body> </html </body> </html> JavaScript Variables
<html> <body> <script type="text/java script"> var first name; first name="Hegel"; document . write(first name); document . write("<br />"); first name="Tove"; document . write(first name); </script> <p>The script above declares a variable, assigns a value to it, displays the value, change the value, and displays the value again.</p> </body> </html> JavaScript Conditional If ... Else
<html> <body> <script type="text/java script"> var d = new Date(); var time = d.get Hours(); if (time < 10) { document.write("<b>Good morning</b>"); } </script> <p> This example demonstrates the If statement. </p> <p> If the time on your browser is less than 10, you will get a "Good morning" greeting. </p> </body> </html>
String Object
<html> <body> <script type="text/java script"> var txt="Hello World!"; document.write (txt.length); </script> </body> </html>
Date Object
<html> <body> <script type="text/java script"> document.write(Date()); </script> </body> </html>
Array Object
<html> <body> <script type="text/java script"> var mycars = new Array(); my cars[0] = "Saab"; my cars[1] = "Volvo"; my cars[2] = "BMW"; for (i=0;i<mycars.length;i++) { document.write(my cars[i] + "</br>"); } </script> </body> </html>
Math Object
<html> <body> <script type="text/java script"> document.write(Math . round(0.60) + "<br>)”; document.write(Math . round(0.50) + "<br>)"; document.write(Math . round(0.49) + "<br>)"; document.write(Math . round(-4.40) + "</br>)"; document.write(Math . round(-4.60)); </script> </body> </html>
Anchor Object
<html> <head> <script type="text/javascript"> function changeLink() { Document . get ElementById('myAnchor').innerHTML="Visit W3Schools"; Document . getElementById('myAnchor').href="http://www.w3schools.com"; Document . getElementById('myAnchor').target="_blank"; } </script> </head> <body> <a id="myAnchor" href="http://www.microsoft.com">Visit Microsoft</a> <input type="button" onclick="changeLink()" value="Change link"> <p>In this example we change the text and the URL of a hyperlink. We also change the target attribute. The target attribute is by default set to "_self", which means that the link will open in the same window. By setting the target attribute to "_blank", the link will open in a new window.</p> </body> </html>
Document Object
<html> <body> <script type="text/javascript"> Document . write("Hello World!"); </script> </body> </html>
Event Object
<html> <head> <script type="text/javascript"> function whichButton(event) { if (event . button==2) { alert("You clicked the right mouse button!"); } else { alert("You clicked the left mouse button!"); } } </script> </head> <body onmousedown="whichButton(event)"> <p>Click in the document. An alert box will alert which mouse button you clicked.</p> </body> </html>
Form and Form Input Objects <html> <head> <script type="text/javascript"> function change Action() { var x=document . getElementById("myForm"); alert ("Original action: " + x .action); x . action="default . asp"; alert("New action: " + x . action); x . submit(); } </script> </head> <body> <form id="myForm" action="js_examples.asp"> Name: <input type="text" value="Mickey Mouse" /> <input type="button" onclick="changeAction()" value="Change action attribute and submit form" /> </form> </body> </html>
Frame, Frameset, and IFrame Objects
<html> <frameset cols="50%,50%"> <frame id = "leftFrame" src="frame_noresize.htm"> <frame id = "rightFrame" src="frame_a.htm"> </frameset> </html>
Image Object
<html> <head> <script type="text/javascript"> function changeSize () { Document . getElementById ("compman").height="250"; Document . getElementById ("compman").width="300"; } </script> </head> <body> <img id="compman" src="compman.gif" width="107" height="98" /> <br /><br /> <input type="button" onclick="changeSize()" value="Change height and width of image"> </body> </html>
Location Object
<html> <head> <script type="text/javascript"> function currLocation () { Alert (window . location); } function newLocation () { window.location="http://www.w3schools.com"; } </script> </head> <body> <input type="button" onclick="currLocation()" value="Show current URL"> <input type="button" onclick="newLocation()" value="Change URL"> </body> </html> |
| Admin | Home | About Society | Aims and Objects | Contact | Sitemap | |
|
Gateway Educational and Welfare Society is an NGO Regd. with Govt. Of Punjab to promote the skills of poor and needy youth of INDIA so that they may earn respectful living hood. Presently the area of functioning of Society is Sangrur Distt. |
||||||
|
Copyright to Starshine India |
||||||