ࡱ> _a^5@ _&bjbj22 (@XXY||||4,$    &$($($($($($($$%R'L$s"L$||  ia$0#0#0#|8  &$0#&$0#"0#R#R#   R##,w$0$R#q(>"q(R#||||q(R#0# SL$L$ #Javascript and HTML Forms Scripting languages such as Javascript and VBScript are used to add functionality to web pages. They can be either included in the web page itself or stored in a separate file. In the latter case, the web page must include a link to the file. Scripts are downloaded with the web page, unlike Java applets and servlets. Applets are not downloaded until the browser reaches the tag. Servlets always execute on the server, not the users computer. But Javascript is downloaded immediately and is executed on the users computer, thus saving time that would otherwise be used for repeated connections to the server. Javascript is not Java, but it shares some syntax with Java and C. It is not strongly typed, so variables do not have to be declared, although they may be. Also statements do not require a terminating semi-colon, but again these may be included. If two statements are on the same line, they must be separated by a semi-colon. Also like Java, Javascript is case sensitive. A Simple Example The following example simply writes the word "Hello" into the box when the user clicks the button. It does not send anything to the server, so the form includes neither an action nor a method attribute. Javascript Hello Example
Scripts may be placed either in the head or body of the page. It is somewhat more common to put them into the head, since it is downloaded first. Also this separates the script from the rest of the page. If the script is external, the head would be as follows: Javascript Hello Example The script file, helloScript.js, would contain only the following code: Functions Functions in Javascript are very simple. They may either perform an action, such as the one above, or return a value. A useful example of the latter is found in the next example. It checks a login form to see that all the boxes have been filled in. This check is performed by the users browser rather than on the server. This saves a significant amount of time when the form contains a number of boxes. This example shows an alert message and returns false, if the box is empty. The false value prevents the action from taking place. However, if both boxes contain text, the value true is returned and the request is sent to the server. Login Form

Please Login

Username:
Password:
 SHAPE \* MERGEFORMAT  Functions can also have parameters. These are not typed, but otherwise they are similar to those in Java methods. An example would be if there were two forms on the same page and the function had to distinguish between them. The function heading might look like function CheckForm (formName) and the submit tag . Objects Javascript also has objects. The one in the next example is a Date object. Like in Java, it must be instantiated before it can be used. There are a number of accessor methods included with this object that get parts of the date, such as the year, month, day, hours, minutes and seconds. The values are those that are stored in the users computer. If the computer time is accurate, the results of the function will be also. The document mentioned in the script is the web page. This will write the date and time on the web page. As with any html page you have to use tags such as
or

to indicate a line or paragraph break. Numerical Data Text boxes contain text, i.e. strings, and not numbers. If the contents of a box are to represent numbers, they must first be parsed before they can be used in a calculation. As in Java, the method to use is parseInt. If the text box, weightBox, contains an integer, the following can be used to change the contents from a string to a number: weight = parseInt (weightBox.value); After a calculation, the answer may turn out to be a double with a number of decimal places. The following will round these to two decimal places: mean = Math.round ((sum / count)* 100) / 100; Occasionally a box may be empty or an answer may not exist. Then Javascript displays NAN. This stands for Not a Number. Checking a box for empty before using it is prudent. Arrays Javascript has arrays that like those in Java begin with index 0. They are instantiated with new. var arrayName = new Array (); They do not have a fixed length, so the number of objects in the array can be found using arrayName.length; Arrays can also be filled initially using parentheses: var prices = new Array (2.89, 1.50, 1.00, 4.95, 3.50); The contents of an array are accessed the same as in Java using square brackets. prices [0] = 3.75; Creating New Windows Javascript can also create a new window with a specified html document in it. This document can either be on your local disk or on the Internet. The following example creates a new window for a date-time page. The code is straightforward. You have to tell the browser where to find the html page and how large the window should be. The following shows a sample script that opens a new window. The first attribute tells where to find the page to open. The second says that it should be opened in a window. The last two give the width and height of the new window (in pixels). Notice that the width and height are enclosed by a single set of double quotation marks since they combine to make up a single attribute. The new window so created appears below. It is a functioning window and can be used like any other html page.          I Z ' 2 V `    -.HJĸsaa#hzhh5B*CJ\aJphh&kB*CJaJphhhhhB*CJaJphhzhhB*CJaJphhzhzB*CJaJphhzB*CJaJphhhB*CJaJphhh5CJaJh8CJaJhCJaJhhCJaJh+lCJaJhM5CJaJh+l5CJaJ&     )RZ\56@gd&kgd+l$a$gd+lY&^&J~1IZm{  +,-.456?Kº}q}f]žUhXCJaJhh5CJaJh&kh&kCJaJh&kB*CJaJph#hzh&k5B*CJ\aJphhzh&kB*CJaJphhRQCJaJh&k6CJaJhYXh&kCJaJh&kCJaJhhCJaJhhhhCJaJhhhhB*CJaJphhzB*CJaJphhzhhB*CJaJph @A;SW.3CGNYt|gdXgd+l&(7:wy !"},I^øøwlhb-hb-CJaJh3 CJaJhb-CJaJjhr|hK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=~WZ"ĊJ#NSzBs2Э}vYC V(pN&)aN .k8'30HҌWE uZ&fs$XCKRKyc'^dAB@s9g܀WtԡA@s N8}BK A5>3Z!RĬԆSoEh9߭bED@m x! 1D j Bi}s5sjx>9} Q95PZ>A ^(rNCԠrN /G9!jPC9J#5!S y6] 4>+ՙ.O3-ƕrW/3S Ix \+6!.te֎I2/pl*|tcckߛk!Zo-8Pn ZΙ:D8ӱ)\Z%-BG8ϥ4q.,"*k9_QoҼPJSڱlOY/4b3!˩< otX˹ "8^y.a)|뱖svD;ŽaQ`+㜵J|6ReJ,\_NItN6w9nR&0bHO$*Ϩv9|PSPXpP^msEs69mQ"9EP\6@"`(rNBTrN0F9 !*PD `P@l?>Qj#B7I$IENDB`@@@ NormalCJ_HaJmH sH tH DAD Default Paragraph FontRiR  Table Normal4 l4a (k(No ListHH 47 Balloon TextCJOJQJ^JaJ__ @  )RZ\5 6 @ A ; S W   . 3 C G N Y t | 1r!"+J]mn8Ph 344cwxbcUVXY\]`000000p00000000000000000000p0000p0@0@00@0@00@00@0@00@00@0@0@0@0@0@0@0@0000@0@0@0@0@0@0@000000p0000000000000000000000000000000000000000000000000000000000 0 0 0  )RZ\5 t | !"+J]8Ph 44bcUVXY\`O900CO900O900"?"# #O900O900O900O900O900AO900O9000O90 00O900O900@0O9004F]O900O900Oy00Oy00Oy000]Oy00Oy00Oy00O900O900O900O900O900O900O90 0O900O900O90#0ЂSM90#0M90#00O9000O90'0fO90'0O90'0O90'0O90'0O90'0DvSO90'0O90'00O900O900O90-00O9040SO9040O9040M900M9040My040Oy040My040M9040M900M900M900O900 O9000J^b"_&@hx"_&^&__l,"$hYAZT(3 @(  R w L #  s"*?`  c $X99?w LT  # w e B S  ?_PptC!N`Q`9*urn:schemas-microsoft-com:office:smarttagsplace <E m{ !  F O ^ v +-ln5>@H?KXdiwM\kznp!0#Y`+1 = E Z \ & 6 < [ a } ,4JMs{9<QUCJdjY`33333333333333333333333333333333338J}i7:}deUX`Y` Carol E Wolf$#e3 %!R`$l)U3r:>s3[lV`a* d:e&k+lb-RQCXzX8CR)Z@MKhw4V47qr|q` *1@] _@UnknownGz Times New Roman5Symbol3& z Arial5& z!Tahoma"qhff77!24JJ3QH)?r:>Javascript and HTML Forms Carol E Wolf Carol E WolfOh+'0 (4 P \ h tJavascript and HTML Forms.ava Carol E Wolfd HaroaroNormal  Carol E Wolfd H22oMicrosoft Word 10.0@@Eb@q"O@՜.+,0  hp  Pace University7JA Javascript and HTML Forms Title  "#$%&'()*+,-./012345678:;<=>?@ABCDEFGHIJKLMOPQRSTUWXYZ[\]`Root Entry FPbData !/1Table9q(WordDocument(@SummaryInformation(NDocumentSummaryInformation8VCompObjj  FMicrosoft Word Document MSWordDocWord.Document.89q