140 likes | 149 Views
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 3. Client Side Scripting JavaScript. What Is It. A client side scripting language It can be inserted into HTML Placed between script tags
E N D
ECMM6018 Enterprise Networking For Electronic CommerceTutorial 3 Client Side Scripting JavaScript
What Is It • A client side scripting language • It can be inserted into HTML • Placed between script tags • It can be referenced externally from a .js file or form part of the HTML file which uses it E.g. <script language="Javascript" src="validate.js"></script> • It can be used in both Netscape Navigator and Microsoft Internet Explorer
More About JavaScript • Object Oriented type language e.g. <html> <head> </head> <body> <script type="text/javascript"> document.write(“Hello World”); </script> </body> </html>
Variables • Memory locations used to store information • Must be not be reserved keywords e.g. break, new, this • They can be any valid identifier • A valid identifier being any series of characters which consist of letter, digits, underscores and dollar signs E.g. account, salary, cla_ss • They cannot begin with a number or contain space e.g. 8mec, java st • JavaScript is Case Sensitive e.g. VaRiAbLe ≠ Variable • Declaration var variablename = some variable
Operators • Arithmetic Operators • Assignment Operators • Comparison Operators • Logical Operators
Arithmetic Operators • () Evaluated first • *, / or % Evaluated second. If several are used they are evaluated left to right • + or - Evaluated last. If several they are several, they are evaluated left to right
Comparison Operators • = = is equal to • != is not equal to • > is greater than • < is less than • >= is greater than or equal to • <= is less than or equal to
Logical Operators • && and • || or • ! not
Functions • A reusable piece of code which is invoked either by an event or when the function is called e.g. of an event, window.alert(“This is a JavaScript Tutorial”) Defining a function function myfunction(argument1,argument2,etc) { some statements } function myfunction() { some statements }
More About Functions • The Return Statement • All functions must have the return statement E.g. function total(a,b) { temp = num1+num2; return temp; } • Function would be called liked this Sum = total(9,10)
Conditional Statements • Conditional statements in JavaScript are used to perform different actions based on different conditions. • If, If-Else statement Syntax if (condition) { code to be executed if condition is true }
Conditional Statements ctd. • Syntax If-Else • If(condition) { code to executed if condition is true } Else { other code is executed }
Algorithm Development • A step-by-step problem-solving procedure • The actions to be executed • The order in which they are to be executed
Useful Links • www.w3schools.com • www.JavaScript.com • www.webreference.com