|
JavaScript is a proven scripting language, which is supported by most browsers. When used within a web page, it gives the Web Author the ability to add client-side pre-programmed interactive functions to your web pages. JavaScript greatly extends the capabilities of HTML. JavaScript is a powerful programming language. Its complexity can rival that of advanced Basic and C++. It can easily produce a number of fascinating browser "stunts" in a very short period of time requiring very little effort. JavaScript, like other programming languages, utilizes the basics of the computer language. If you have heard of the Universal Grammer discovered by linguistic scientists at the turn of the century, you may agree that computer languages have sort of the same thing going for them too. What follows is a terse overview of what you can expect from JavaScript. It is by no means complete and a good book from QUE would go much more in depth. But, if you're looking into the language this may be of some help.
Var MyVar_String = "String Data" Var MyVar_Str_Array=new Array(100) MyVar is a numeric type of a variable. Positive and negative numbers can be stored. Var_String is a variable that can hold string or text type data. Variable MyVar_Str_Array is an array of strings. The 100, of course is the size of the array. This would represent something similar to the size of 100 copies of the variable MyVar_String, referenced by MyVar_Str_Array[#] to indicate which string you are referring to.
while () { } for (,,) {}
displayarea.document.write("Some happy HTML code");
Simply put, until the variable x starting at 1 is no longer less than the variable arraycounter (initialized elsewhere) it will process the statements within the brackets. The "x+=1" portion says increment x by one through each repetition through the loop. In most of the JavaScript books you will find a reference to the statements included with JavaScript.
-- decrement + add - subtract * multiply / divide % modulus & and ^ Xor | or < less than > greater than == equal <= guess >= guess != Not equal += assign addition to -= assign subtraction of << and >> can shift bits if you like
For a complete list go to Netscape's Method List Of honorable mention are:
1. Doing a submit can be done from OnLoad or another Event using code like this:
<input type="hidden" name="mdb" value="\example.mdb"> <input type="hidden" name="tbl" value="MyTable"> <input type="hidden" name="template" value="\htms\return.htm"> <input type="submit" name="goforit" value="Submit"> <nput type="text" name="DB_productname" size=20> </FORM> B. Create a function that calls the form.submit()
function Myfunc() {
</SCRIPT> C. Launch it!
</BODY>
function names are case sensitive function showme() {
</SCRIPT> B. Where the form is testform and the object is checkme as seen here:
<INPUT type="text" name="checkme" onBlur="checkinput()"> <INPUT type="button" Value="JavaScript" onClick="Scoobydooby()"> </FORM> 3. Checking user input is another valuable capability:
function checkinput() { // better done by passing "this" but for clarity...
var lcheckstring=checkstring.toLowerCase() if ( lcheckstring =="" ) {
if (lcheckstring.indexOf("e") >= 0) {
</SCRIPT> B. From the Form, where the Form is testform and the object is checkme as seen here:
<INPUT type="text" name="checkme" onBlur="checkinput()"> <INPUT type="button" Value="JavaScript" onClick="Scoobydooby()"> </FORM> 4. Browser Detection:
function WhatVersion () {
document.write (navigator.appVersion+"old<P>"); </SCRIPT> 5. I want to substitute that cold, grey "Submit" button for my own happy image. I can use the same kind of code for form.submit, by making the event related to the image:
< img border=0 src="myownbutton.gif" width=40 height=20 alt=Submit> Where the Myfunc() routine is identical to the one in item #1 above. 6. I want to load variables from a search result. Can I program the template to do this? Yes, by using frames. Here is the template code. You would need one frame for making the request and one for displaying the data:
function LoadVars() {
description=new Array (100); price=new Array (100); id=new Array (100); shortdesc=new Array (100); shipprice=new Array (100); var arraycounter=0; var x=0; arraycounter +=1; ProductName [arraycounter] ="&&productname&&"; description [arraycounter] ="&&longdesc&&"; price[arraycounter]="&&price&&"; id[arraycounter]="&&prodid&&"; shortdesc[arraycounter]="&&desc&&"; shipprice[arraycounter]="&&ship&&"; *&
for (x=1;x } </SCRIPT> <body background="mybackground.gif" onLoad="LoadVars()"> 7. I see that you can write from one frame to another. Can you break this down for me?
THE VARIABLES MUST NOT BE WITHIN THE BRACKETS OR THEY WILL NOT BE GLOBAL.
description=new Array(100); price=new Array(100); id=new Array(100); shortdesc=new Array(100); shipprice=new Array(100); var arraycounter=0; 9. Create windows:
FeatureList B. windowFeatures is a comma-separated list of any of the following options and values:
location[=yes|no]|[=1|0] directories[=yes|no]|[=1|0] status[=yes|no]|[=1|0] menubar[=yes|no]|[=1|0] scrollbars[=yes|no]|[=1|0] resizable[=yes|no]|[=1|0] width=pixels height=pixels 10. Suppose you have a page that has been moved to a different location. Instead of going through your site and changing every page that references the page's old location, use this "URL-grabber" to send your viewers to the new location:
11. setTimeout is a JavaScript 1.0 compliant command. This means that you can set a timer on any JavaScript-capable browser for the purpose of scheduling some task for the future:
The JavaScript Handbook Netscape's JavaScript Guide Netscape's JavaScript Resources JScript, JavaScript Documentation Download (JSDOC.exe 500KB)
The JavaScript section at Developer.com An excellent collection of links and articles about JavaScript Development.
|
| © 95-00 InfoDial, Inc. | Privacy Policy |