RaysWebClass.Com |
JScript is short for Javascript. JScript fills a gap that ASP can not fill. ASP is, as you now know, a very powerful programming language but it has one flaw; it does not run on the client side (end user) -- ASP is server side only. Therefore any Dynamic HTML such as mouse over, image swapping, or field verification (which is best done on the client-side) is accomplished by using JavaScript.
<html>Notice the <script> and </script> tags, and the document.write which is similar to the Response.Write in ASP.
<head>
<title>JScript Example One</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>
<html>
<head>
<title>JScript Example Two</title>
</head>
<body onLoad="alert('Welcome!')" onUnload="alert('Good Bye!')">
</body>
</html>
<html>history.back() will make the browser move to the page your browser displayed previously to this page (the same things as clicking the Back button on your browser.)
<head>
<title>JScript Example Three</title>
</head>
<body>
<input type="button" onClick="history.back()">
</body>
</html>
For JScript to read or write to an element within a web page it needs to find the element. The follow chart is a hierarchical naming convention used by JavaScript to identify objects and their properties:For example, to write Hello in a textbox named text1 in a form on the page you would do:![]()
document.form.text1.value="Hello"
Using ID's can simplify this ever further. For example if I create a textbox with an ID="Ray", I can access it by simply usingdocument.all.Ray.value="Hello" The .all will search the entire document looking for an object with an ID="Ray".
The following chart is a list of objects and their related events:
Object Event Action Textboxes onBlur Tab away from this object or click on another object. Use this to verify field content. onFocus Tab to or click to this object. onSelect Select text. onChange Change text. onMouseOver Move the mouse over the object. onMouseOut Move the mouse off the object. Button onClick Mouse over and Click or Tab Enter. Radio onClick Mouse over and Click or Tab Enter. HyperLink onMouseOver Move the mouse over the object. onMouseOut Move the mouse off the object. onClick Mouse over and Click or Tab Enter. Body onLoad After the web page has completed downloading. onUnload Upon moving to another web page.
Lastly I would like to point out the differences between JavaScript and Java. The only thing the two languages have in common are the first four letter of there names! Well, not really. Javascript is a sub-set of the Java language, but JavaScript is written in the HTML code, Java is not. It's compiled using a Java compiler and placed separately on the server from the HTML that runs it. The following chart will display some of the major differenced between the two languages:
JavaScript JAVA Designed by Netscape Designed by Sun Microsystems Resides and acts upon the entire Web page Resides out side the Web page and acts only upon the region where it is displayed Usable by non-programmers Requires programming experience Run's from within the client's browser Run's from standalone code outside the browser
Put all the above examples of JScript into one page.
Create a folder in the wwwroot called JScript and save this project as JScript51.html.