ActiveNET HTML, JS, CSS JavaScript. JavaScript
|
|
- Jonathan Gibbs
- 5 years ago
- Views:
Transcription
1 JavaScript 1. Introduction to JavaScript 2. JavaScript Vs java 3. Diff b/w Interpreted programs Vs Compiled programs Vs Compiled-interpreted programs 4. Diff b/w Object Oriented Vs Object Based Programming Languages? 5. Why we choose JavaScript? 6. Where to place JavaScript 7. JavaScript (variable declarations, control structures, events, objects, function declarations and calling them) 8. Hierarchy of JavaScript 9. Examples Introduction to JavaScript JavaScript is Netscape developed object based scripting language used in millions of web pages and server applications across World Wide Web. JavaScript Vs java Java is an Object Oriented Programming language. JavaScript is Object based Scripting language. Java is strictly typed programming language means variables are declared with specific data types. In JavaScript variables are declared with var keyword, no variable sticks to any datatype hence we can assign value of any data type such as int, long, float, double, Boolean, Date, String etc to the same variable. Java is compiled and interpreted programming language. JavaScript is interpreted programming language on client system at runtime. JavaScript runs on client system. Java runs on server system. Diff b/w Interpreted programs Vs Compiled programs Vs Compiled-interpreted programs In both the cases the program is written using text based commands called source code. In compiled programming languages the source code is passed through compiler to get executable code which can directly runs on Operating system because exec files contains OS binary instructions. Examples of compiled programming languages are C, C++. In interpreted programming languages the source is code is passed through interpreter that converts each line into OS understandable binary instruction. Example of interpreted programming language is PERL (Practical Extraction and Reporting Language). JavaScript is also an interpreted scripting language but it runs on browser. Java is a compiled and interpreted programming language. Compiler compiles java source code into intermediatery called byte code. The Java interpreter reads line-by-line of byte code and converts it into OS binary format. Hence Page 1
2 its slightly slower than compiled programming language but because of both compiled and interpreted it became OS independent. Diff b/w Object Oriented Vs Object Based Programming Languages? The simple difference is Object Oriented Programming language supports inheritance which extends the functionality of a class by inheriting from another class. But whereas Object Based Programming language supports only association between classes but not inheritance.. That means we can use existing classes functionality given by programming language vendor but not user defined classes. Why we choose JavaScript? JavaScript is the only scripting language that most of the browsers supports such as FireFox, IE, Netscape, Opera, Avanti, Hot Java etc. Netscape supports only JavaScript where as IE supports both JavaScript, JScript and VBScript. Netscape supports Layers whereas IE supports IFrames. JavaScript is originally developed by Netscape, later standardized by ECMA (European Computer Manufacturing Association) called ECMAScript. JavaScript JavaScript gives HTML designers a programming tool. JavaScript can put dynamic text into an HTML page. JavaScript can react to events. JavaScript can read and write HTML elements. JavaScript can be used to validate data. JavaScript can be used to detect the visitor s browser. JavaScript can be used to create Cookies. Comparison between JavaScript and java JavaScript Interpreted (not compiled) by client Object-based. Code uses built-in extensible objects, but no classes or inheritance Code integrated with, and embedded in HTML Variable data types are not declared (loose typing) Secure. Cannot write to hard disk. Java Compiled on server before execution on client. Object-oriented. Applets consists of object classes and inheritance. Applets distinct from HTML (accessed from HTML pages) Variable data types must be declared (strong typing) Secure. Cannot write to hard disk. Window, String, Date, Math, Number, Array, Boolean, RegExpr, XMLHttpRequest, ActiveXObject Where to place JavaScript JS1.html <SCRIPT language= JavaScript > document.write( This text is written from JavaScript ); Page 2
3 Note that there are two tags used to implement JavaScript. Variable declarations As same as Java in JavaScript also variable must start with any character (a-z, A-Z, _). Variables must not begin with number but can contain number in middle of the variable name. In variables we can assign values of different data types such as integers, floating points, booleans, Strings, Arrays and Object of other classes. var keyword must be used to declare variable var i=3; // first int value 3 is assigned to i variable. i= Three ; // next Three the String value is assigned to i variable. i=true; // to the same variable boolean value true is assigned. i=10.24; // to the same variable double value is assigned. While declaring variables the keyword var must be used only for the first time. From thereafter variable can be directly used without var keyword. Type conversion functions isnan() eval() parseint() parsefloat() typeof operator isnan The isnan() function determines whether a value is an illegal number (Not-a-Number). This function returns true if the value is NaN, and false if not. document.write(isnan(123)+ "<br />"); document.write(isnan(-1.23)+ "<br />"); document.write(isnan(5-2)+ "<br />"); document.write(isnan(0)+ "<br />"); document.write(isnan("hello")+ "<br />"); document.write(isnan("2005/12/12")+ "<br />"); eval() function The eval() function evaluates or executes an argument. If the argument is an expression, eval() evaluates the expression. If the argument is one or more JavaScript statements, eval() executes the statements. eval("x=10;y=20;document.write(x*y)"); document.write("<br />" + eval("2+2")); document.write("<br />" + eval(x+17)); Page 3
4 parseint() function The parseint() function parses a string and returns an integer. document.write(parseint("10") + "<br />"); document.write(parseint("10.33") + "<br />"); document.write(parseint(" ") + "<br />"); document.write(parseint(" 60 ") + "<br />"); document.write(parseint("40 years") + "<br />"); document.write(parseint("he was 40") + "<br />"); parsefloat() function The parsefloat() function parses a string and returns a floating point number. document.write(parsefloat("10") + "<br />"); document.write(parsefloat("10.33") + "<br />"); document.write(parsefloat(" ") + "<br />"); document.write(parsefloat(" 60 ") + "<br />"); document.write(parsefloat("40 years") + "<br />"); document.write(parsefloat("he was 40") + "<br />"); typeof operator The "typeof" operator in JavaScript allows you to probe the data type of its operand, such as whether a variable is string, numeric, or even undefined. The below simple example alerts the data type of the variable "myvar". var myvar=5; alert(typeof myvar); // alerts number string boolean object null undefined Arrays Array declaration and Initialization JS2.html <SCRIPT language= JavaScript > var tree=new Array(4); function displayarray() { tree[0]= Roots ; tree[1]= Trunk ; tree[2]= Branches ; tree[3]= Leaves ; window.alert(tree); Page 4
5 <BODY onload= displayarray() > Dynamic Array declaration and Initialization var tree = new Array('Roots', 'Trunk', 'Branches', 'Leaves'); window.alert(tree); Auto Array Increment tree[4]= Twigs ; // If we assign another value to tree array variable its size increases. JavaScript Operators Math Operators Operator Meaning Example + Addition Subtraction 6-2 * Multiplication 5*3 / Division 15/3 % Modulus 43%10 ++ Increment var i=10; i++; // i value is Decrement var i=10; i--; // i value is 9 JS3.html <body> <script type="text/javascript"> <!-- var two = 2 var ten = 10 var linebreak = "<br />" document.write("two plus ten = ") var result = two + ten document.write(result) document.write(linebreak) document.write("ten * ten = ") result = ten * ten document.write(result) document.write(linebreak) document.write("ten / two = ") result = ten / two document.write(result) //--> </body> Bitwise Operators Operator Usage Description Page 5
6 Bitwise AND a & b Returns a one in each bit position for which the corresponding bits of both operands are ones. Bitwise OR a b Bitwise XOR a ^ b Bitwise NOT ~a Left Shift a << b Sign propagation a >> b right shift Zero fill right shift a >>> b JavaScript events 1. onload The onload event occurs when the user agent finishes loading a window or all frames within a FRAMESET. This attribute may be used with BODY and FRAMESET elements. 2. onunload The onunload event occurs when the user agent removes a document from a window or frame. This attribute may be used with BODY and FRAMESET elements. 3. onclick The onclick event occurs when the pointing device button is clicked over an element. This attribute may be used with most elements. 4. ondblclick Page 6
7 The ondblclick event occurs when the pointing device button is double clicked over an element. This attribute may be used with most elements. 5. onmousedown The onmousedown event occurs when the pointing device button is pressed over an element. This attribute may be used with most elements. 6. onmouseup The onmouseup event occurs when the pointing device button is released over an element. This attribute may be used with most elements. 7. onmouseover The onmouseover event occurs when the pointing device is moved onto an element. This attribute may be used with most elements. 8. onmousemove The onmousemove event occurs when the pointing device is moved while it is over an element. This attribute may be used with most elements. 9. onmouseout The onmouseout event occurs when the pointing device is moved away from an element. This attribute may be used with most elements. 10. onfocus The onfocus event occurs when an element receives focus either by the pointing device or by tabbing navigation. This attribute may be used with the following elements: A, AREA, LABEL, INPUT, SELECT, TEXTAREA, and BUTTON. 11. onblur The onblur event occurs when an element loses focus either by the pointing device or by tabbing navigation. It may be used with the same elements as onfocus. 12. onkeypress The onkeypress event occurs when a key is pressed and released over an element. This attribute may be used with most elements. 13. onkeydown The onkeydown event occurs when a key is pressed down over an element. This attribute may be used with most elements. 14. onkeyup The onkeyup event occurs when a key is released over an element. This attribute may be used with most elements. 15. onsubmit The onsubmit event occurs when a form is submitted. It only applies to the FORM element. 16. onreset The onreset event occurs when a form is reset. It only applies to the FORM element. 17. onselect The onselect event occurs when a user selects some text in a text field. This attribute may be used with the INPUT and TEXTAREA elements. 18. onchange The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus. This attribute applies to the following elements: INPUT, SELECT, and TEXTAREA. JavaScript Objects Window object Window Object Properties The window object represents an open window in a browser. Property Description Page 7
8 closed defaultstatus document frames history innerheight innerwidth length location name navigator opener outerheight outerwidth pagexoffset pageyoffset parent screen screenleft screentop screenx Returns a Boolean value indicating whether a window has been closed or not Sets or returns the default text in the statusbar of a window Returns the Document object for the window (See Document object) Returns an array of all the frames (including iframes) in the current window Returns the History object for the window (See History object) Returns the inner height of a window's content area Returns the inner width of a window's content area Returns the number of frames (including iframes) in a window Returns the Location object for the window (See Location object) Sets or returns the name of a window Returns the Navigator object for the window (See Navigator object) Returns a reference to the window that created the window Returns the outer height of a window, including toolbars/scrollbars Returns the outer width of a window, including toolbars/scrollbars Returns the pixels the current document has been scrolled (horizontally) from the upper left corner of the window Returns the pixels the current document has been scrolled (vertically) from the upper left corner of the window Returns the parent window of the current window Returns the Screen object for the window (See Screen object) Returns the x coordinate of the window relative to the screen Returns the y coordinate of the window relative to the screen Returns the x coordinate of the window relative to the screen Page 8
9 screeny self status top Returns the y coordinate of the window relative to the screen Returns the current window Sets or returns the text in the statusbar of a window Returns the topmost browser window Window Object Methods Method alert() atob() blur() btoa() clearinterval() cleartimeout() close() confirm() createpopup() focus() moveby() moveto() open() print() prompt() resizeby() Description Displays an alert box with a message and an OK button Decodes a base-64 encoded string Removes focus from the current window Encodes a string in base-64 Clears a timer set with setinterval() Clears a timer set with settimeout() Closes the current window Displays a dialog box with a message and an OK and a Cancel button Creates a pop-up window Sets focus to the current window Moves a window relative to its current position Moves a window to the specified position Opens a new browser window Prints the content of the current window Displays a dialog box that prompts the visitor for input Resizes the window by the specified pixels Page 9
10 resizeto() scroll() scrollby() scrollto() setinterval() settimeout() stop() Resizes the window to the specified width and height This method has been replaced by the scrollto() method. Scrolls the content by the specified number of pixels Scrolls the content to the specified coordinates Calls a function or evaluates an expression at specified intervals (in milliseconds) Calls a function or evaluates an expression after a specified number of milliseconds Stops the window from loading JS1.html <html> <head> <script> function welcome() { window.alert("hai good morning, Welcome to all of you to my Java script session. Hope you will enjoy. Thank you- Surya"); </head> <body onload="welcome()"> </body> </html> JS2.html <html> <head> <script> function ask() { var status=window.confirm("would you like to close this window"); if(status==true) { window.close(); </head> <body onload="ask()"> </body> </html> JS3.html <html> <head> <script> function new1() { Page 10
11 // open ActiveNET site // window.open(" olbar=no,location=no,statusbar=no,scrollbars=no,menubar=no,zlock=yes,width=800,height=500,resizable=no"); var w1=window.open("","window1","titlebar=no,toolbar=no,location=no,statusb ar=no,scrollbars=no,menubar=no,z-lock=yes, width=500, height=300, resizable=no"); w1.document.writeln("<form action=''>"); w1.document.writeln("<input type='text' name=' ' value=''>"); w1.document.writeln("<input type='submit' name='submit' value='submit you ID'>"); w1.document.writeln("</form>"); </head> <body onload="new1()"> </body> </html> JS4.html <html> <head> <script> function take() { var name=window.prompt("enter you name","chinni/bujji/chitti"); alert( Hello +name+", rename your name to Pokiri / Basha / Shivaji"); </head> <body onload="take()"> </body> </html> JS4.html <html> <head> <script> function examine() { alert("keep an observation like that, press OK and find out what happens"); window.settimeout("call()", 1000); function call() { window.close(); </head> <body onload="examine()"> </body> </html> JS5.html <html> <head> Page 11
12 <script> function welcome() { alert("keaka"); document.writeln("su...per color"); // function document.fgcolor="yellow"; // property document.bgcolor="blue"; // property document.link="red"; // property document.alink="magenta"; // property document.vlink="gray"; // property </head> <body onload="welcome()"> </body> </html> JS6.html <FORM> <H3>BackGround Colors</H3> <INPUT TYPE="button" VALUE=" Red " onclick="document.bgcolor ='red'"> <INPUT TYPE="button" VALUE=" White " onclick="document.bgcolor = 'white'"> <H3>ForeGround Colors</H3> <INPUT TYPE="button" VALUE=" Blue " onclick="document.fgcolor ='blue'"> <INPUT TYPE="button" VALUE=" Green " onclick="document.fgcolor = 'green'"> </FORM> JS7.html <SCRIPT> function dupe() { window.open(location.href, "windowname", ""); <BODY onload='dupe()'> </BODY> JS8.html <SCRIPT> function disp() { window.document.writeln(location.protocol+"\n"); window.document.writeln(location.host+"\n"); window.document.writeln(location.hostname+"\n"); window.document.writeln(location.port+"\n"); window.document.writeln(location.pathname+"\n"); window.document.writeln(location.href+"\n"); Page 12
13 <BODY onload=' disp ()'> </BODY> JS9.html <SCRIPT> function nav(command) { if(command=='back') history.back(); else if(command=='forward') history.forward(); else if(command=='go') history.go(parseint(window.document.frm1.loc.value)); else if(command=='len') window.document.writeln(history.length); else history.current(); <BODY> <FORM name="frm1"> <INPUT type="button" name="button" value="back" onclick="nav('back')"> <INPUT type="button" name="button" value="forward" onclick="nav('forward')"> <INPUT type="text" name="loc" value="2"> <INPUT type="button" name="button" value="go" onclick="nav('go')"> <INPUT type="button" name="button" value="len" onclick="nav('len')"> </FORM> </BODY> JS10.html <SCRIPT> function disp() { document.write("<p><b>navigator.appcodename =</B> "+navigator.appcodename); document.write("<p><b>navigator.appname =</B> "+navigator.appname); document.write("<p><b>navigator.appversion =</B> "+navigator.appversion); document.write("<p><b>navigator.useragent =</B> "+navigator.useragent); document.write("<p><b>navigator.mimetypes[0].type =</B> "+navigator.mimetypes[0].type); document.write("<p><b>navigator.plugins[0].name =</B> "+navigator.plugins[0].name); document.write("<p><b>navigator.language =</B> "+navigator.language); document.write("<p><b>navigator.platform =</B> "+navigator.platform); Page 13
14 <BODY onload="disp()"> </BODY> JS11.html <SCRIPT LANGUAGE="JAVASCRIPT"> var smonth = "September"; var nyear = 2000; var nday = 27; var sdate = smonth + " " + nday + ", " + nyear; Then we created this button: <FORM> <INPUT TYPE="button" VALUE="sDate" onclick="alert(sdate)"> </FORM> JS12.html <SCRIPT LANGUAGE="JAVASCRIPT"> var sdate = new Date(); <FORM> <INPUT TYPE="button" VALUE="sDate" onclick="alert(sdate)"> </FORM> JS13.html <SCRIPT LANGUAGE="JAVASCRIPT"> var d=new Date(); window.document.write(d+"<br>"); window.document.write(d.getdate()+"<br>"); window.document.write(d.getday()+"<br>"); window.document.write(d.getfullyear()+"<br>"); window.document.write(d.gethours()+"<br>"); window.document.write(d.getmilliseconds()+"<br>"); window.document.write(d.getminutes()+"<br>"); window.document.write(d.getmonth()+"<br>"); window.document.write(d.getseconds()+"<br>"); window.document.write(d.gettime()+"<br>"); window.document.write(d.gettimezoneoffset()+"<br>"); window.document.write(d.getutcdate()+"<br>"); window.document.write(d.getutcday()+"<br>"); window.document.write(d.getutcfullyear()+"<br>"); window.document.write(d.getutchours()+"<br>"); window.document.write(d.getutcmilliseconds()+"<br>"); window.document.write(d.getutcminutes()+"<br>"); window.document.write(d.getutcmonth()+"<br>"); window.document.write(d.getutcseconds()+"<br>"); window.document.write(d.getyear()+"<br>"); JS14.html (Clock) Page 14
15 <SCRIPT LANGUAGE="JavaScript"> // define the variables we need for the program var timestr, datestr; var now, hours, minutes, seconds; function clock() { now = new Date(); // now becomes an instants of the Date Object // the gethours() pulls out the Hours from the new now Object hours = now.gethours(); // the getminutes() pulls out the Minutes from the new now Object minutes = now.getminutes(); // the getseconds() pulls out the Seconds from the new now Object seconds = now.getseconds(); // below we want to create a String, so here we are concatenating // an Empty String with a number and we end up with a string. timestr = "" + hours; // minutes are shown as :12 or :09 for example, the ternary operator does just that // if minutes are < 10 then add :0 before the number of minutes // else if the minutes are > 9 then just add : before the number of minutes timestr += ((minutes < 10)? ":0" : ":") + minutes; timestr += ((seconds < 10)? ":0" : ":") + seconds; // once we have created the time string then place that value into the FORM's "time" field document.clock.time.value = timestr; // the settimeout Method says // I want you to call clock() every 1000 milliseconds or every 1 second // since there is no prefix for the settimeout - // it means that it is method of the Window Object settimeout("clock()", 1000); <BODY onload="clock()"> The onload Event Handler is executed when the Document or Frameset is fully loaded, which means that all Images have been downloaded and displayed, all subframes have loaded, any Java Applets and Plugins (Navigator) have started running, and so on. The function clock() will be called after "everything" is loaded The NAME of the FORM is "clock" <FORM NAME="clock"> The NAME of the text field is "time". NOTE: the VALUE is an Empty String waiting to be filled with the "TIME". Time: <INPUT TYPE="text" NAME="time" VALUE=""> </FORM> </BODY> Page 15
16 JS15.html <SCRIPT LANGUAGE="JavaScript"> function loaded() { alert( Window loaded ); function unloaded() { alert( Window unloaded ); <BODY onload="loaded()"onunload="unloaded()"> </BODY> JS16.html (onclick) <SCRIPT LANGUAGE="JavaScript"> function clicked() { alert( Button Clicked ); <BODY> <FORM> <INPUT type= button name= b1 value= Button1 onclick= clicked() > </FORM> </BODY> JS17.html onmousedown <SCRIPT LANGUAGE="JavaScript"> function msd() { alert("mouse down"); <BODY onmousedown="msd()"> </BODY> JS18.html onmouseover, onmousemove, onmouseout <SCRIPT LANGUAGE="JavaScript"> function mso() { alert("mouse over"); function mm() { Page 16
17 alert("mouse move"); function mo() { alert("mouse out"); <BODY> <IMG src="activenet_logo3.jpg" onmouseover="mso()" onmousemove="mm()" onmouseout="mo()"> </BODY> JS19.html onfocus, onblur <SCRIPT LANGUAGE="JavaScript"> function onfs() { alert("on focus"); function onblr() { alert("on blur"); function prmtsbmt() { var stat=prompt("would you like to submit this form to server, Press Y for yes and N for no", "Y"); if(stat=='y') { window.document.frm1.submit(); alert("submission khatam, your form is submitted"); <BODY> <FORM name="frm1" action="./tell_me_where_to_go"> <INPUT type="text" name="name" value="enter your name" onfocus="onfs()" onblur="onblr()"> <INPUT type="text" name=" " value="enter your " onblur="prmtsbmt()"> </FORM> </BODY> JS20.html <SCRIPT LANGUAGE="JavaScript"> function dispmp() { window.status=window.event.screenx+", "+window.event.screeny; <BODY onmousemove="dispmp()"> </BODY> Page 17
18 JS21.html <SCRIPT LANGUAGE="JavaScript"> function cnfrm() { var stat=prompt("confirm your form submission", "Y"); if(stat=="y") { alert("submitted"); <BODY> <FORM name="frm1" action="./tell_me_where_to_go" onsubmit="cnfrm()"> <INPUT type="text" name="name" value="enter your name"> <INPUT type="text" name=" " value="enter your "> <INPUT type="submit" name="submit" value="cccl...i...k..."> </FORM> </BODY> JS22.html <SCRIPT LANGUAGE="JavaScript"> function chng() { alert(window.frm1.name.value); function dispslct() { alert("you like : "+window.frm1.slct.value); function slct() { alert(window.frm1.name.value); <BODY> <FORM name="frm1" action="./tell_me_where_to_go"> <INPUT type="text" name="name" value="enter your name" onchange="chng()"> <SELECT name="slct" onchange="dispslct()"> <OPTION value="india">india</option> <OPTION value="pak">pakistan</option> <OPTION value="china">china</option> <OPTION value="singapore">singapore</option> <OPTION value="japan">japan</option> </SELECT> </FORM> </BODY> JS23.html <head> Page 18
19 <script language="javascript"> function newxmlhttprequest() { var xmlreq = false; if (window.xmlhttprequest) { // Create XMLHttpRequest object in non-microsoft browsers xmlreq = new XMLHttpRequest(); alert("xmlhttprequest object is created"); else if (window.activexobject) { // Create XMLHttpRequest via MS ActiveX try { // Try to create XMLHttpRequest in later versions of Internet Explorer xmlreq = new ActiveXObject("Msxml2.XMLHTTP"); alert("msxml2.xmlhttp object is created"); catch (e1) { // Failed to create required ActiveXObject try { // Try version supported by older versions of Internet Explorer xmlreq = new ActiveXObject("Microsoft.XMLHTTP"); alert("microsoft.xmlhttp object is created"); catch (e2) { return xmlreq; </head> <BODY onload="newxmlhttprequest()"> </BODY> JS24.html <script language="javascript"> function readxml() { alert("before changing DIV"); document.getelementbyid("results").innerhtml="sample div modified"; var mydoc = new ActiveXObject("Microsoft.XMLDOM"); mydoc.load("sample.xml"); // mydoc.loadxml("<emps><emp><eno>1</eno></emp><emp><eno>2</eno></emp></emps>"); alert(mydoc.documentelement.childnodes.length); <BODY onload="readxml()"> <div name="div" id="results" style="color:red; font-weight:bold;"> Sample div </div> </BODY> Page 19
20 JS25.html <script language="javascript"> function readxml() { var select=document.createelement("select"); var option1=document.createelement("option"); option1.setattribute("value", "Jet Airways"); option1.appendchild(document.createtextnode("jet Airways")); var option2=document.createelement("option"); option2.setattribute("value", "Sahara"); option2.appendchild(document.createtextnode("sahara")); var option3=document.createelement("option"); option3.setattribute("value", "Go Air"); option3.appendchild(document.createtextnode("go Air")); var option4=document.createelement("option"); option4.setattribute("value", "KingFisher"); option4.appendchild(document.createtextnode("kingfisher")); var option5=document.createelement("option"); option5.setattribute("value", "Paramount Airways"); option5.appendchild(document.createtextnode("paramount Airways")); var option6=document.createelement("option"); option6.setattribute("value", "Air Deccan"); option6.appendchild(document.createtextnode("air Deccan")); select.appendchild(option1); select.appendchild(option2); select.appendchild(option3); select.appendchild(option4); select.appendchild(option5); select.appendchild(option6); document.getelementbyid("air").appendchild(select); <BODY onload="readxml()"> <SPAN name="air" id="air" style="color:red; font-weight:bold;"> Choose airways </SPAN><BR/> <SPAN name="source" id="source" style="color:red; font-weight:bold;"> Select Source </SPAN><BR/> <SPAN name="dest" id="dest" style="color:red; font-weight:bold;"> Page 20
21 Select Destination </SPAN><BR/> </BODY> JS26.html IFrame using MSXMLDOM A.html Page A B.html Page B iframe.html <TITLE>Changing Element Attributes</TITLE> <SCRIPT LANGUAGE="JavaScript"> function change_image() { document.all.myiframe.src="b.html"; <BODY> <IFRAME id=myiframe src="a.html"> </IFRAME> <BUTTON onclick=change_image()>change contents of the IFRAME</BUTTON> </BODY> String Object The String object is used to manipulate a stored piece of text. String objects are created with new String(). Syntax var txt = new String("string"); or more simply: var txt = "string"; Property Constructor length Prototype Description Returns the function that created the String object's prototype Returns the length of a string Allows you to add properties and methods to an object String Object Methods Method charat() charcodeat() concat() Description Returns the character at the specified index Returns the Unicode of the character at the specified index Joins two or more strings, and returns a copy of the joined strings Page 21
22 fromcharcode() indexof() lastindexof() match() replace() search() slice() split() substr() substring() tolowercase() touppercase() valueof() Converts Unicode values to characters Returns the position of the first found occurrence of a specified value in a string Returns the position of the last found occurrence of a specified value in a string Searches for a match between a regular expression and a string, and returns the matches Searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring Searches for a match between a regular expression and a string, and returns the position of the match Extracts a part of a string and returns a new string Splits a string into an array of substrings Extracts the characters from a string, beginning at a specified start position, and through the specified number of character Extracts the characters from a string, between two specified indices Converts a string to lowercase letters Converts a string to uppercase letters Returns the primitive value of a String object JS27.html <SCRIPT LANGUAGE="JavaScript"> var str=new String( ActiveNET ); // var str= ActiveNET ; window.document.writeln(str.constructor+ <br> ); window.document.writeln(str.length+ <br> ); window.document.writeln(str.prototype+ <br> ); window.document.writeln(str.charat(6)+ <br> ); window.document.writeln(str.concat( Infor )+ <br> ); window.document.writeln(str.fromcharcode(2)+ <br> ); window.document.writeln(str.indexof( T )+ <br> ); window.document.writeln(str.lastindexof( T )+ <br> ); var str1="the rain in SPAIN stays mainly in the plain"; var pattern1=/ain/gi; window.document.writeln(str1.matches(pattern1)+ <br> ); // Displays ain wherever exist irrespective of case sensitive window.document.writeln(str.replace( e, E )+ <br> ); window.document.writeln(str.search( ACT )+ <br> ); // returns -1 if string is not found var str2= Hello happy world window.document.writeln(str2.slice(0)+ <br> ); // from 0 th index all characters are returned window.document.writeln(str2.slice(6)+ <br> ); // from 6 th index all characters are returned window.document.writeln(str2.slice(-6)+ <br> ); Page 22
23 // from last 6 characters are returned window.document.writeln(str2.slice(0,1)+ <br> ); // from 0 th index 1 character is returned window.document.writeln(str2.slice(6,11)+ <br> ); // from 6 th index to 11 th index characters are returned var str3= How are you doing today ; window.document.writeln(str3.split()+ <br> ); // String displayed as it is window.document.writeln(str3.split( )+ <br> ); // wherever white space character occurs they are all splitted as Strings window.document.writeln(str3.split( )+ <br> ); // Each character in String splits as character and displayed window.document.writeln(str3.split(, 3)+ <br> ); // Wherever space occurs they are splitted as Strings but only first 3 Strings are displayed window.document.writeln(str.substr(3)+ <br> ); // From 3 rd index all characters are displayed window.document.writeln(str.substr(3,5)+ <br> ); // From 3 rd index to 5 th index String retrieved and displayed as String window.document.writeln(str.tolowercase()+ <br> ); window.document.writeln(str.touppercase()+ <br> ); RegExp Object A regular expression is an object that describes a pattern of characters. Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text. Syntax var patt=new RegExp(pattern,modifiers); or more simply: var patt=/pattern/modifiers; pattern specifies the pattern of an expression modifiers specify if a search should be global, case-sensitive, etc. Modifiers Modifiers are used to perform case-insensitive and global searches: Modifier i g M Description Perform case-insensitive matching Perform a global match (find all matches rather than stopping after the first match) Perform multiline matching Brackets Brackets are used to find a range of characters: Expression [abc] Description Find any character between the brackets Page 23
24 [^abc] Find any character not between the brackets [0-9] Find any digit from 0 to 9 [A-Z] [a-z] [A-z] [adgk] [^adgk] (red blue green) Find any character from uppercase A to uppercase Z Find any character from lowercase a to lowercase z Find any character from uppercase A to lowercase z Find any character in the given set Find any character outside the given set Find any of the alternatives specified Metacharacters Metacharacters are characters with a special meaning: Metacharacter Description. Find a single character, except newline or line terminator \w Find a word character \W Find a non-word character \d Find a digit \D Find a non-digit character \s Find a whitespace character \S Find a non-whitespace character \b Find a match at the beginning/end of a word \B Find a match not at the beginning/end of a word \0 Find a NUL character \n Find a new line character \f Find a form feed character \r Find a carriage return character \t Find a tab character \v Find a vertical tab character \xxx \xdd \uxxxx Find the character specified by an octal number xxx Find the character specified by a hexadecimal number dd Find the Unicode character specified by a hexadecimal number xxxx Quantifiers Quantifier Description n+ Matches any string that contains at least one n n* Matches any string that contains zero or more occurrences of n n? Matches any string that contains zero or one occurrences of n n{x Matches any string that contains a sequence of X n's n{x,y Matches any string that contains a sequence of X to Y n's Page 24
25 n{x, Matches any string that contains a sequence of at least X n's n$ Matches any string with n at the end of it ^n Matches any string with n at the beginning of it?=n Matches any string that is followed by a specific string n?!n Matches any string that is not followed by a specific string n RegExp Object Methods Method compile() exec() test() Description Compiles a regular expression Tests for a match in a string. Returns the first match Tests for a match in a string. Returns true or false compile() The compile() method is used to compile a regular expression during execution of a script. The compile() method can also be used to change and recompile a regular expression. Syntax RegExpObject.compile(regexp,modifier) Parameter Regexp Modifier Description A regular expression Specifies the type of matching. "g" for a global match, "i" for a case-insensitive match and "gi" for a global, case-insensitive match JS28.html var str="every man in the world! Every woman on earth!"; var patt=/man/g; var str2=str.replace(patt,"person"); document.write(str2+"<br />"); patt=/(wo)?man/g; patt.compile(patt); str2=str.replace(patt,"person"); document.write(str2); Output Every person in the world! Every woperson on earth! Every person in the world! Every person on earth! exec() method The exec() method tests for a match in a string. This method returns the matched text if it finds a match, otherwise it returns null. Syntax RegExpObject.exec(string) Page 25
26 Parameter String Description Required. The string to be searched JS29.html var str="hello world!"; //look for "Hello" var patt=/hello/g; var result=patt.exec(str); document.write("returned value: " + result); //look for "W3Schools" patt=/w3schools/g; result=patt.exec(str); document.write("<br />Returned value: " + result); Output Returned value: Hello Returned value: null test() method The test() method tests for a match in a string. This method returns true if it finds a match, otherwise it returns false. Syntax RegExpObject.test(string) Parameter String Description Required. The string to be searched JS30.html var str="hello world!"; //look for "Hello" var patt=/hello/g; var result=patt.test(str); document.write("returned value: " + result); //look for "W3Schools" patt=/w3schools/g; result=patt.test(str); document.write("<br />Returned value: " + result); Output Returned value: true Returned value: false Page 26
27 Array What is an Array? An array is a special variable, which can hold more than one value, at a time. If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this: var car1="saab"; var car2="volvo"; var car3="bmw"; However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300? The best solution here is to use an array! An array can hold all your variable values under a single name. And you can access the values by referring to the array name. Each element in the array has its own ID so that it can be easily accessed. Create an Array An array can be defined in three ways. The following code creates an Array object called mycars: 1: var mycars=new Array(); // regular array (add an optional integer mycars[0]="saab"; // argument to control array's size) mycars[1]="volvo"; mycars[2]="bmw"; 2: var mycars=new Array("Saab","Volvo","BMW"); // condensed array 3: var mycars=["saab","volvo","bmw"]; // literal array Note: If you specify numbers or true/false values inside the array then the variable type will be Number or Boolean, instead of String. Access an Array You can refer to a particular element in an array by referring to the name of the array and the index number. The index number starts at 0. The following code line: document.write(mycars[0]); will result in the following output: Saab Modify Values in an Array To modify a value in an existing array, just add a new value to the array with a specified index number: mycars[0]="opel"; Now, the following code line: document.write(mycars[0]); will result in the following output: Opel Array Object Properties Property constructor Description Returns the function that created the Array object's prototype Page 27
28 Length prototype Sets or returns the number of elements in an array Allows you to add properties and methods to an object Array Object Methods Method concat() indexof() join() pop() push() reverse() shift() slice() sort() splice() tostring() unshift() valueof() Description Joins two or more arrays, and returns a copy of the joined arrays Joins all elements of an array into a string Removes the last element of an array, and returns that element Adds new elements to the end of an array, and returns the new length Reverses the order of the elements in an array Removes the first element of an array, and returns that element Selects a part of an array, and returns the new array Sorts the elements of an array Adds/Removes elements from an array Converts an array to a string, and returns the result Adds new elements to the beginning of an array, and returns the new length Returns the primitive value of an array concat() method The concat() method is used to join two or more arrays. This method does not change the existing arrays, it only returns a copy of the joined arrays. JS31.html var parents = ["Jani", "Tove"]; var children = ["Cecilie", "Lone"]; var family = parents.concat(children); document.write(family); Output Jani,Tove,Cecilie,Lone Join three arrays JS32.html var parents = ["Jani", "Tove"]; var brothers = ["Stale", "Kai Jim", "Borge"]; var children = ["Cecilie", "Lone"]; var family = parents.concat(brothers, children); document.write(family); Page 28
29 Output Jani,Tove,Stale,Kai Jim,Borge,Cecilie,Lone join() method The join() method joins all elements of an array into a string, and returns the string. The elements will be separated by a specified separator. The default separator is comma (,). Syntax array.join(separator) JS33.html var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write(fruits.join() + "<br />"); document.write(fruits.join("+") + "<br />"); document.write(fruits.join(" and ")); pop() method The pop() method removes the last element of an array, and returns that element. Note: This method changes the length of an array! Syntax array.pop() JS34.html var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write(fruits.pop() + "<br />"); document.write(fruits + "<br />"); document.write(fruits.pop() + "<br />"); document.write(fruits); Output Mango Banana,Orange,Apple Apple Banana,Orange push() method The push() method adds new elements to the end of an array, and returns the new length. Note: This method changes the length of an array! Syntax: array.push(element1, element2,..., elementx) JS35.html Page 29
30 var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write(fruits.push("kiwi") + "<br />"); document.write(fruits.push("lemon","pineapple") + "<br />"); document.write(fruits); Output 5 7 Banana,Orange,Apple,Mango,Kiwi,Lemon,Pineapple reverse() method The reverse() method reverses the order of the elements in an array (makes the last element first, and the first element last). Note: This method changes the original array! Syntax array.reverse() JS36.html var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write(fruits.reverse()); Output Mango,Apple,Orange,Banana shift() method The shift() method removes the first element of an array, and returns that element. Note: This method changes the length of an array! Syntax array.shift() JS37.html var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write(fruits.shift() + "<br />"); document.write(fruits + "<br />"); document.write(fruits.shift() + "<br />"); document.write(fruits); Output Banana Orange,Apple,Mango Page 30
31 Orange Apple,Mango slice() method The slice() method selects a part of an array, and returns the new array. Note: The original array will not be changed. Syntax array.slice(start, end) JS38.html var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write(fruits.slice(0,1) + "<br />"); document.write(fruits.slice(1) + "<br />"); document.write(fruits.slice(-2) + "<br />"); document.write(fruits); Ouput Banana Orange,Apple,Mango Apple,Mango Banana,Orange,Apple,Mango sort() method The sort() method sorts the elements of an array. Note: This method changes the original array! Syntax array.sort(sortfunc) JS39.html var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write(fruits.sort()); Output Apple,Banana,Mango,Orange splice() method The splice() method adds and/or removes elements to/from an array, and returns the removed element(s). Note: This method changes the original array! Syntax array.splice(index,howmany,element1,...,elementx) JS40.html var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write("added: " + fruits.splice(2,0,"lemon") + "<br />"); document.write(fruits); Page 31
32 Output Added: Banana,Orange,Lemon,Apple,Mango JS41.html var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write("removed: " + fruits.splice(2,1,"lemon") + "<br />"); document.write(fruits); Output Removed: Apple Banana,Orange,Lemon,Mango JS42.html var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write("removed: " + fruits.splice(2,2,"lemon") + "<br />"); document.write(fruits); Output Removed: Apple,Mango Banana,Orange,Lemon tostring() method The tostring() method converts an array to a string and returns the result. Note: The returned string will separate the elements in the array with commas. JS43.html var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write(fruits.tostring()); Output Banana,Orange,Apple,Mango unshift() method The unshift() method adds new elements to the beginning of an array, and returns the new length. Note: This method changes the length of an array! Syntax array.unshift(element1,element2,..., elementx) JS44.html Page 32
33 var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write(fruits.unshift("kiwi") + "<br />"); document.write(fruits.unshift("lemon","pineapple") + "<br />"); document.write(fruits); Output 5 7 Lemon,Pineapple,Kiwi,Banana,Orange,Apple,Mango Math Object The Math object allows you to perform mathematical tasks. Math Object Properties Property Description E Returns Euler's number (approx ) LN2 Returns the natural logarithm of 2 (approx ) LN10 Returns the natural logarithm of 10 (approx ) LOG2E Returns the base-2 logarithm of E (approx ) LOG10E Returns the base-10 logarithm of E (approx ) PI Returns PI (approx ) SQRT1_2 Returns the square root of 1/2 (approx ) SQRT2 Returns the square root of 2 (approx ) Math Object Methods Method abs(x) acos(x) asin(x) atan(x) atan2(y,x) ceil(x) cos(x) exp(x) floor(x) log(x) max(x,y,z,...,n) min(x,y,z,...,n) pow(x,y) Description Returns the absolute value of x Returns the arccosine of x, in radians Returns the arcsine of x, in radians Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians Returns the arctangent of the quotient of its arguments Returns x, rounded upwards to the nearest integer Returns the cosine of x (x is in radians) Returns the value of E x Returns x, rounded downwards to the nearest integer Returns the natural logarithm (base E) of x Returns the number with the highest value Returns the number with the lowest value Returns the value of x to the power of y random() Returns a random number between 0 and 1 Page 33
34 round(x) sin(x) sqrt(x) tan(x) Rounds x to the nearest integer Returns the sine of x (x is in radians) Returns the square root of x Returns the tangent of an angle JS45.html <html> <body> var b1=new Boolean(0); var b2=new Boolean(1); var b3=new Boolean(""); var b4=new Boolean(null); var b5=new Boolean(NaN); var b6=new Boolean("false"); document.write("0 is boolean "+ b1 +"<br />"); document.write("1 is boolean "+ b2 +"<br />"); document.write("an empty string is boolean "+ b3 + "<br />"); document.write("null is boolean "+ b4+ "<br />"); document.write("nan is boolean "+ b5 +"<br />"); document.write("the string 'false' is boolean "+ b6 +"<br />"); </body> </html> Output 0 is boolean false 1 is boolean true An empty string is boolean false null is boolean false NaN is boolean false The string 'false' is boolean true Number Object The Number object is an object wrapper for primitive numeric values. Number objects are created with new Number(). Syntax var num = new Number(value); Number Object Properties Property constructor MAX_VALUE MIN_VALUE NEGATIVE_INFINITY POSITIVE_INFINITY Description Returns the function that created the Number object's prototype Returns the largest number possible in JavaScript Returns the smallest number possible in JavaScript Represents negative infinity (returned on overflow) Represents infinity (returned on overflow) Page 34
35 prototype Number Object Methods Method toexponential(x) tofixed(x) toprecision(x) tostring() valueof() Allows you to add properties and methods to an object Description Converts a number into an exponential notation Formats a number with x numbers of digits after the decimal point Formats a number to x length Converts a Number object to a string Returns the primitive value of a Number object Page 35
CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.
What is JavaScript? HTML and CSS concentrate on a static rendering of a page; things do not change on the page over time, or because of events. To do these things, we use scripting languages, which allow
More informationNote: Java and JavaScript are two completely different languages in both concept and design!
Java Script: JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight programming language JavaScript is usually embedded directly
More information710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8
INDEX Symbols = (assignment operator), 56 \ (backslash), 33 \b (backspace), 33 \" (double quotation mark), 32 \e (escape), 33 \f (form feed), 33
More informationINTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 15: JavaScript loops, Objects, Events - Spring 2011
INTRODUCTION TO WEB DEVELOPMENT AND HTML Lecture 15: JavaScript loops, Objects, Events - Spring 2011 Outline Selection Statements (if, if-else, switch) Loops (for, while, do..while) Built-in Objects: Strings
More informationLECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli
LECTURE-2 Functions review HTML Forms Arrays Exceptions Events 1 JAVASCRIPT FUNCTIONS, REVIEW Syntax function (params) { // code Note: Parameters do NOT have variable type. 1. Recall: Function
More informationCITS1231 Web Technologies. JavaScript Math, String, Array, Number, Debugging
CITS1231 Web Technologies JavaScript Math, String, Array, Number, Debugging Last Lecture Introduction to JavaScript Variables Operators Conditional Statements Program Loops Popup Boxes Functions 3 This
More informationSuch JavaScript Very Wow
Such JavaScript Very Wow Lecture 9 CGS 3066 Fall 2016 October 20, 2016 JavaScript Numbers JavaScript numbers can be written with, or without decimals. Extra large or extra small numbers can be written
More informationThe Number object. to set specific number types (like integer, short, In JavaScript all numbers are 64bit floating point
Internet t Software Technologies JavaScript part three IMCNE A.A. 2008/09 Gabriele Cecchetti The Number object The JavaScript Number object does not allow you to set specific number types (like integer,
More informationClient-Side Web Technologies. JavaScript Part I
Client-Side Web Technologies JavaScript Part I JavaScript First appeared in 1996 in Netscape Navigator Main purpose was to handle input validation that was currently being done server-side Now a powerful
More informationPES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II
PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore 560 100 WEB PROGRAMMING Solution Set II Section A 1. This function evaluates a string as javascript statement or expression
More informationJavaScript. History. Adding JavaScript to a page. CS144: Web Applications
JavaScript Started as a simple script in a Web page that is interpreted and run by the browser Supported by most modern browsers Allows dynamic update of a web page More generally, allows running an arbitrary
More informationLECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli
LECTURE-3 Exceptions JS Events 1 EXCEPTIONS Syntax and usage Similar to Java/C++ exception handling try { // your code here catch (excptn) { // handle error // optional throw 2 EXCEPTIONS EXAMPLE
More informationThe first sample. What is JavaScript?
Java Script Introduction JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari. In this lecture
More informationJavaScript CS 4640 Programming Languages for Web Applications
JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation
More informationJavaScript. History. Adding JavaScript to a page. CS144: Web Applications
JavaScript Started as a simple script in a Web page that is interpreted and run by the browser Supported by most modern browsers Allows dynamic update of a web page More generally, allows running an arbitrary
More informationBy the end of this section of the practical, the students should be able to:
By the end of this section of the practical, the students should be able to: Write JavaScript to generate HTML Create simple scripts which include input and output statements, arithmetic, relational and
More informationWhat Is JavaScript? A scripting language based on an object-orientated programming philosophy.
What Is JavaScript? A scripting language based on an object-orientated programming philosophy. Each object has certain attributes. Some are like adjectives: properties. For example, an object might have
More informationCISH-6510 Web Application Design and Development. Overview of JavaScript. Overview
CISH-6510 Web Application Design and Development Overview of JavaScript Overview What is JavaScript? History Uses of JavaScript Location of Code Simple Alert Example Events Events Example Color Example
More informationIntroduction to Computer Programming in Python Dr. William C. Bulko. Data Types
Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have
More informationLecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript
Lecture 3: The Basics of JavaScript Wendy Liu CSC309F Fall 2007 Background Origin and facts 1 2 Needs for Programming Capability XHTML and CSS allows the browser to passively display static content How
More informationProduct Price Formula extension for Magento2. User Guide
Product Price Formula extension for Magento2 User Guide version 1.0 Page 1 Contents 1. Introduction... 3 2. Installation... 3 2.1. System Requirements... 3 2.2. Installation...... 3 2.3. License... 3 3.
More informationJavaScript CS 4640 Programming Languages for Web Applications
JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation
More informationA.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies
Internet t Software Technologies JavaScript part one IMCNE A.A. 2008/09 Gabriele Cecchetti Why introduce JavaScript To add dynamicity and interactivity to HTML pages 2 What s a script It s a little interpreted
More informationCSC Web Programming. Introduction to JavaScript
CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its
More informationwrite vs. writeln Prompting as Page Loads Today s Goals CSCI 2910 Client/Server-Side Programming Intermediate File vs. HTML Output
CSCI 2910 Client/Server-Side Programming Topic: JavaScript Part 2 Today s Goals Today s lecture will cover: More objects, properties, and methods of the DOM The Math object Introduction to form validation
More informationa Why JavaScript? jonkv interactivity on the web CGI JavaScript Java Applets Netscape LiveScript JavaScript 1: Example
Why JavaScript? 2 JavaScript JavaScript the language Web page manipulation with JavaScript and the DOM 1994 1995: Wanted interactivity on the web Server side interactivity: CGI Common Gateway Interface
More informationEvents: another simple example
Internet t Software Technologies Dynamic HTML part two IMCNE A.A. 2008/09 Gabriele Cecchetti Events: another simple example Every element on a web page has certain events which can trigger JavaScript functions.
More informationIntroduction to DHTML
Introduction to DHTML HTML is based on thinking of a web page like a printed page: a document that is rendered once and that is static once rendered. The idea behind Dynamic HTML (DHTML), however, is to
More informationChapter 2. Outline. Simple C++ Programs
Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.
More informationPrinceton University COS 333: Advanced Programming Techniques A Subset of JavaScript
Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Program Structure function sqr(i) var result; // Otherwise result would be global. result = i * i; //
More informationPrinceton University COS 333: Advanced Programming Techniques A Subset of JavaScript
Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Program Structure function sqr(i) var result; // Otherwise result would be global. result = i * i; //
More informationCOMS 469: Interactive Media II
COMS 469: Interactive Media II Agenda Review Ch. 7: HTML Forms Ch. 9: String Manipulation Review Object Oriented Programming JavaScript Native Objects Browser Objects Review OOP Terminology Object Properties
More informationE ECMAScript, 21 elements collection, HTML, 30 31, 31. Index 161
A element, 108 accessing objects within HTML, using JavaScript, 27 28, 28 activatediv()/deactivatediv(), 114 115, 115 ActiveXObject, AJAX and, 132, 140 adding information to page dynamically, 30, 30,
More informationSo don t copy files or photocopy - Share! Share these FREE Courses! End User License Agreement Use of this package is governed by the following terms:
Share these FREE Courses! Why stuff your friend s mailbox with a copy of this when we can do it for you! Just e-mail them the link info http://www.trainingtools.com Make sure that you visit the site as
More information3 The Building Blocks: Data Types, Literals, and Variables
chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating
More informationJavascript Hierarchy Objects Object Properties Methods Event Handlers. onload onunload onblur onfocus
Javascript Hierarchy Objects Object Properties Methods Event Handlers Window Frame Location History defaultstatus frames opener parent scroll self status top window defaultstatus frames opener parent scroll
More informationCOMS 469: Interactive Media II
COMS 469: Interactive Media II Agenda Review Ch. 5: JavaScript An Object-Based Language Ch. 6: Programming the Browser Review Data Types & Variables Data Types Numeric String Boolean Variables Declaring
More informationFundamentals of Website Development
Fundamentals of Website Development CSC 2320, Fall 2015 The Department of Computer Science Events handler Element with attribute onclick. Onclick with call function Function defined in your script or library.
More informationJavaScript is described in detail in many books on the subject, and there is excellent tutorial material at
JavaScript (last updated April 15, 2013: LSS) JavaScript is a scripting language, specifically for use on web pages. It runs within the browser (that is to say, it is a client- side scripting language),
More informationNew Perspectives on Creating Web Pages with HTML. Tutorial Objectives
New Perspectives on Creating Web Pages with HTML Tutorial 9: Working with JavaScript Objects and Events 1 Tutorial Objectives Learn about form validation Study the object-based nature of the JavaScript
More informationJavaScript Handling Events Page 1
JavaScript Handling Events Page 1 1 2 3 4 5 6 7 8 Handling Events JavaScript JavaScript Events (Page 1) An HTML event is something interesting that happens to an HTML element Can include: Web document
More informationAbout the Tutorial. Audience. Prerequisites. Copyright and Disclaimer
About the Tutorial JavaScript is a lightweight, interpreted programming language. It is designed for creating network-centric applications. It is complimentary to and integrated with Java. JavaScript is
More informationSession 16. JavaScript Part 1. Reading
Session 16 JavaScript Part 1 1 Reading Reading Wikipedia en.wikipedia.org/wiki/javascript / p W3C www.w3.org/tr/rec-html40/interact/scripts.html Web Developers Notes www.webdevelopersnotes.com/tutorials/javascript/
More informationChapter 4: Basic C Operators
Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional
More informationChapter 4 Basics of JavaScript
Chapter 4 Basics of JavaScript JavaScript/EcmaScript References The official EcmaScript, third edition, specification http://www.ecma-international.org/publications/files/ecma-st/ecma-262.pdf A working
More information1$ 5 ! $ 6 4 * Source: 0 "!*! 0! * 8 97 ?!$ 5 0 *! 4! $ 0 : * ' () 7;7 7<7
!#! # %! ' ()!* +, -.!/ *! * 1 !!
More informationCGS 3066: Spring 2015 JavaScript Reference
CGS 3066: Spring 2015 JavaScript Reference Can also be used as a study guide. Only covers topics discussed in class. 1 Introduction JavaScript is a scripting language produced by Netscape for use within
More informationDocument Object Model (DOM)
Document Object Model (DOM) HTML DOM The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure
More information5. Strict mode use strict ; 6. Statement without semicolon, with semicolon 7. Keywords 8. Variables var keyword and global scope variable 9.
Javascript 1) Javascript Implementation 1. The Core(ECMAScript) 2. DOM 3. BOM 2) ECMAScript describes 1. Syntax 2. Types 3. Statements 4. Keywords 5. Reserved words 6. Operators 7. Objects 3) DOM 1. Tree
More informationPearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world
Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world Visit us on the World Wide Web at: www.pearsoned.co.uk Pearson Education Limited 2014
More informationCOMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts
COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool
More informationCSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial
CSI31 Lecture 5 Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial 1 3.1 Numberic Data Types When computers were first developed, they were seen primarily as
More informationSession 6. JavaScript Part 1. Reading
Session 6 JavaScript Part 1 Reading Reading Wikipedia en.wikipedia.org/wiki/javascript Web Developers Notes www.webdevelopersnotes.com/tutorials/javascript/ JavaScript Debugging www.w3schools.com/js/js_debugging.asp
More informationJAVASCRIPT BASICS. Handling Events In JavaScript. In programing, event-driven programming could be a programming
Handling s In JavaScript In programing, event-driven programming could be a programming paradigm during which the flow of the program is set by events like user actions (mouse clicks, key presses), sensor
More informationJAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)
Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 1 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) WHO
More informationLike most objects, String objects need to be created before they can be used. To create a String object, we can write
JavaScript Native Objects Broswer Objects JavaScript Native Objects So far we have just been looking at what objects are, how to create them, and how to use them. Now, let's take a look at some of the
More informationJavaScript Introduction
JavaScript Introduction Web Technologies I. Zsolt Tóth University of Miskolc 2016 Zsolt Tóth (UM) JavaScript Introduction 2016 1 / 31 Introduction Table of Contents 1 Introduction 2 Syntax Variables Control
More informationIntroduction to JavaScript
127 Lesson 14 Introduction to JavaScript Aim Objectives : To provide an introduction about JavaScript : To give an idea about, What is JavaScript? How to create a simple JavaScript? More about Java Script
More informationJavaScript s role on the Web
Chris Panayiotou JavaScript s role on the Web JavaScript Programming Language Developed by Netscape for use in Navigator Web Browsers Purpose make web pages (documents) more dynamic and interactive Change
More informationCSC Javascript
CSC 4800 Javascript See book! Javascript Syntax How to embed javascript between from an external file In an event handler URL - bookmarklet
More informationJAVASCRIPT. sarojpandey.com.np/iroz. JavaScript
JAVASCRIPT 1 Introduction JAVASCRIPT is a compact, object-based scripting language for developing client Internet applications. was designed to add interactivity to HTML pages. is a scripting language
More informationRegular Expressions. Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl)
Regular Expressions Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl) JavaScript started supporting regular expressions in
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationBasics of JavaScript. Last Week. Needs for Programming Capability. Browser as Development Platform. Using Client-side JavaScript. Origin of JavaScript
Basics of JavaScript History of the Web XHTML CSS Last Week Nan Niu (nn@cs.toronto.edu) CSC309 -- Fall 2008 2 Needs for Programming Capability XHTML and CSS allows the browser to passively display static
More informationPIC 40A. Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers. Copyright 2011 Jukka Virtanen UCLA 1 04/24/17
PIC 40A Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers 04/24/17 Copyright 2011 Jukka Virtanen UCLA 1 Objects in JS In C++ we have classes, in JS we have OBJECTS.
More informationMaths Functions User Manual
Professional Electronics for Automotive and Motorsport 6 Repton Close Basildon Essex SS13 1LE United Kingdom +44 (0) 1268 904124 info@liferacing.com www.liferacing.com Maths Functions User Manual Document
More informationJavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore
JavaScript and XHTML Prof. D. Krupesha, PESIT, Bangalore Why is JavaScript Important? It is simple and lots of scripts available in public domain and easy to use. It is used for client-side scripting.
More informationCOMS 469: Interactive Media II
COMS 469: Interactive Media II Agenda Review Ch. 8: Windows and Frames (pp. 263-299) Ch. 11: Storing Info: Cookies (pp. 367-389) Review HTML Forms String Manipulation Objects document.myform document.forms[0]
More informationTypes and Expressions. Chapter 3
Types and Expressions Chapter 3 Chapter Contents 3.1 Introductory Example: Einstein's Equation 3.2 Primitive Types and Reference Types 3.3 Numeric Types and Expressions 3.4 Assignment Expressions 3.5 Java's
More informationUNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?
UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? A 1: A text editor is a program that helps you write plain text (without any formatting) and save it to a file. A good example is
More informationIndian Institute of Technology Kharagpur. Javascript Part III. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.
Indian Institute of Technology Kharagpur Javascript Part III Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Kharagpur, INDIA Lecture 27: Javascript Part III On completion, the student
More informationEngineering Problem Solving with C++, Etter/Ingber
Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input
More informationJavascript Bignum Extensions
1 Javascript Bignum Extensions Version 2018-05-27 Author: Fabrice Bellard i Table of Contents 1 Introduction................................................... 1 2 Operator overloading..........................................
More informationUNIT-4 JAVASCRIPT. Prequisite HTML/XHTML. Origins
UNIT-4 JAVASCRIPT Overview of JavaScript JavaScript is a sequence of statements to be executed by the browser. It is most popular scripting language on the internet, and works in all major browsers, such
More informationPlace User-Defined Functions in the HEAD Section
JavaScript Functions Notes (Modified from: w3schools.com) A function is a block of code that will be executed when "someone" calls it. In JavaScript, we can define our own functions, called user-defined
More informationJScript Reference. Contents
JScript Reference Contents Exploring the JScript Language JScript Example Altium Designer and Borland Delphi Run Time Libraries Server Processes JScript Source Files PRJSCR, JS and DFM files About JScript
More informationChapter 2 Working with Data Types and Operators
JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics
More informationJavaScript Pocket Reference, 2nd Edition By David Flanagan. Publisher: O'Reilly Pub Date: October 2002 ISBN: Pages: 136 Slots: 0.
JavaScript Pocket Reference, 2nd Edition By David Flanagan Table of Contents Reviews Reader Reviews Errata Publisher: O'Reilly Pub Date: October 2002 ISBN: 0-596-00411-7 Pages: 136 Slots: 0.5 The JavaScript
More informationLecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)
Lecture 14 Introduction to JavaScript Mr. Mubashir Ali Lecturer (Dept. of dr.mubashirali1@gmail.com 1 Outline What is JavaScript? Embedding JavaScript with HTML JavaScript conventions Variables in JavaScript
More informationDOM Primer Part 2. Contents
DOM Primer Part 2 Contents 1. Event Programming 1.1 Event handlers 1.2 Event types 1.3 Structure modification 2. Forms 2.1 Introduction 2.2 Scripting interface to input elements 2.2.1 Form elements 2.2.2
More informationFull file at https://fratstock.eu Tutorial 2: Working with Operators and Expressions
Tutorial 2: Working with Operators and Expressions TRUE/FALSE 1. You can add a dynamic effect to a Web site using ontime processing. ANS: F PTS: 1 REF: JVS 54 2. You can not insert values into a Web form
More informationJAVASCRIPT BASICS. JavaScript Math Functions. The Math functions helps you to perform mathematical tasks
JavaScript Math Functions Functions The Math functions helps you to perform mathematical tasks in a very way and lot of inbuilt mathematical functions which makes the programmers life easier. Typical example
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationJavaScript: The Basics
JavaScript: The Basics CISC 282 October 4, 2017 JavaScript A programming language "Lightweight" and versatile Not universally respected Appreciated in the web domain Adds programmatic functionality to
More informationOperations. Making Things Happen
Operations Making Things Happen Object Review and Continue Lecture 1 2 Object Categories There are three kinds of objects: Literals: unnamed objects having a value (0, -3, 2.5, 2.998e8, 'A', "Hello\n",...)
More informationANSI C Programming Simple Programs
ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double
More informationUNIT -II. Language-History and Versions Introduction JavaScript in Perspective-
UNIT -II Style Sheets: CSS-Introduction to Cascading Style Sheets-Features- Core Syntax-Style Sheets and HTML Style Rle Cascading and Inheritance-Text Properties-Box Model Normal Flow Box Layout- Beyond
More informationJAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)
Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 2 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA
More information5.4 JavaScript Objects and Methods
CHAPTER 5: JavaScript Basics 117 5.4 JavaScript Objects and Methods JavaScript Objects and Properties Aggregate real world data types An object has properties and methods o Constructors for creating objects
More informationHTML5 and CSS3 More JavaScript Page 1
HTML5 and CSS3 More JavaScript Page 1 1 HTML5 and CSS3 MORE JAVASCRIPT 3 4 6 7 9 The Math Object The Math object lets the programmer perform built-in mathematical tasks Includes several mathematical methods
More informationOrdinary Differential Equation Solver Language (ODESL) Reference Manual
Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE
More informationCOMP519 Web Programming Lecture 12: JavaScript (Part 3) Handouts
COMP519 Web Programming Lecture 12: JavaScript (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationC++ Programming Lecture 11 Functions Part I
C++ Programming Lecture 11 Functions Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department Introduction Till now we have learned the basic concepts of C++. All the programs
More informationJavascript Methods. concat Method (Array) concat Method (String) charat Method (String)
charat Method (String) The charat method returns a character value equal to the character at the specified index. The first character in a string is at index 0, the second is at index 1, and so forth.
More informationTEXTAREA NN 2 IE 3 DOM 1
778 TEXTAREA Chapter 9DOM Reference TEXTAREA NN 2 IE 3 DOM 1 The TEXTAREA object reflects the TEXTAREA element and is used as a form control. This object is the primary way of getting a user to enter multiple
More informationDocuments and computation. Introduction to JavaScript. JavaScript vs. Java Applet. Myths. JavaScript. Standard
Introduction to Prof. Ing. Andrea Omicini II Facoltà di Ingegneria, Cesena Alma Mater Studiorum, Università di Bologna andrea.omicini@unibo.it Documents and computation HTML Language for the description
More informationPROGRAMMING WITH MATLAB DR. AHMET AKBULUT
PROGRAMMING WITH MATLAB DR. AHMET AKBULUT OVERVIEW WEEK 1 What is MATLAB? A powerful software tool: Scientific and engineering computations Signal processing Data analysis and visualization Physical system
More informationCOMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts
COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool
More information3Lesson 3: Functions, Methods and Events in JavaScript Objectives
3Lesson 3: Functions, Methods and Events in JavaScript Objectives By the end of this lesson, you will be able to: 1.3.1: Use methods as. 1.3.2: Define. 1.3.3: Use data type conversion methods. 1.3.4: Call.
More information