Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Programming JScript Six Scripting functions Discuss functions Password Example.

Similar presentations


Presentation on theme: "Introduction to Programming JScript Six Scripting functions Discuss functions Password Example."— Presentation transcript:

1 Introduction to Programming JScript Six Scripting functions Discuss functions Password Example

2 Elements of jScript Coding <!-- //1) Package Jscript --> // 6) start execution // 2) declare variables // 3) Input data // 4) Process data // 5) Output data // Jscript code > Pop ups Etc.

3 Scripting Functions Declare Script Packaging – … –Function() Define Variables and Allocate memory –var variable1name,variable2name; –HTML Object References (tagid.property.value) Input data –Window.prompt(), Process Data –parseInt(), +,-,*,/,if, if/else, for, … Output Data –document.writeln(), document.write(), window.alert() Start Execution ( Events) –onload, onclick, onmouseover

4 Syntax and Notation //comment { … } encapsulates program statements ;ends and separates all lines \Escape character –\n new line \t tab \” insert double quote Example –Window.write(“\”this \n is \n 3 lines \””) “this is 3 lines ” Case sensitive

5 Script Packaging Script inside tags Code inside HTML Comments Raw statements execute immediately Functions enclosed in curly brackets { } // is the Jscript comment <!-- document.writeln(“write immediately" ); function A(input) { document.writeln(“writewhen referenced" ); } // -->

6 Simple JScript Example Simple JScript Example <!-- // Script code in here document.writeln(" Welcome to JavaScript Programming! " ); // -->

7 Define Variables Use the var statement to define variables –var variable1name, variable2name; A variable name is the container for a value Scope –if defined outside a function the variable is global and can be used anywhere –If defined inside a function it is only meaningful inside the function HTML Object References can be used as variables var result = tagname.innertext; The result of functions can be used output variables var result = parseInt(“23”);

8 INPUT Special function –Returnvalue=window.prompt(“question”,def); HTML Object reference with tag ID – inner text –Reference the text inside the tag as tagname.innerText HTML Object reference with Form name – –Reference the input as formName.inputFieldName.value Eaxmple: var text = formName.inputFieldName.value;

9 Process Data Mathematical like assignment statements –Result = expression –Expression is some combination of variables and operators (Var1+var2)*var3 Operator examples +,-,*,/, Control Statements –Change the flow depending upon a condition Examples: if, if/else, for, … If(expression1 Operator Expression2) { If true do this}; If(10 10 is less than 11 ”}; –Operators ==,!=,>, =,<= Built in functions –parseFloat ( string), math.cos(rad),

10 Output Document.write(“HTML Code” + variable + “ more HTML Code”); –Html code between quotes –Variable : any value of a variable could be integer, float, string, function return or an HTML oject reference –Do not split lines inside quotes Document.writeln(“Html whole line”) adds a ne line Object reference assignment –Tagid.innertext = “print this line”

11 Start Execution Statements inside script tags are executed automatically when the page loads <!-- document.writeln(" this line is executed " ); // --> Functions are executed when referenced <!-- function A(input) { document.writeln(“only type”+input+”when referenced" ); } // --> Referenced by HTML Events in the body or from other functions – –function B(){ A(“ A is called”); }

12 Get JScripts from the Web Java scripts are relatively hard to write and harder to debug Many scripts are available free on the web Search for JavaScript source on your favorite search engine –Try http://javascriptsource.comhttp://javascriptsource.com –I got this clock examplethis clock example Since client side source is readily viewable You can copy most scripts directly from sites In most cases some editing is required –Need to know enough HTML and Jscript to do this


Download ppt "Introduction to Programming JScript Six Scripting functions Discuss functions Password Example."

Similar presentations


Ads by Google