Presentation on theme: "/ 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8."— Presentation transcript:
/ 251 Internet Applications Ahmed M. Zeki Sem – / Chapter 8
/ 255 document.writeln( Welcome to the Page ); A string of characters can be contained between the double quotation () marks or single quotation () marks. The browser's document object represents the HTML document currently being displayed in the browser. The document object allows a script programmer to specify HTML text to be displayed in the HTML document.
/ 256 The browser contains a complete set of objects that allow script programmers to access and manipulate every element of an HTML document. An object resides in the computer's memory and contains information used by the script. The term object normally implies that attributes (data) and behaviors (methods) are associated with the object. The object's methods use the attributes to provide useful services to the client of the object - the script that calls the methods.
/ 257 The document object's writeln method writes a line of HTML text in the HTML document being displayed. Method writeln instructs the browser to display the string of HTML text based on the contents of the string. The parentheses following a method name contain the arguments that the method requires to perform its task (or its action).
/ 258 If the string contains HTML elements, the browser interprets these elements and renders them on the screen. Using writeln to write a line of HTML text into the document does not necessarily write a line of text in the HTML document. The text displayed in the browser is entirely dependent on the contents of the string written, which is subsequently rendered by the browser. The browser will interpret the HTML elements as it normally does to render the final text in the document.
/ 2511 Each write or writeln statement resumes writing characters where the last write or writeln stopped writing characters. Sometimes it is useful to display information in windows called dialog boxes that "pop up" on the screen to grab the user's attention. Dialog boxes are typically used to display important messages to the user who is browsing the Web page. The browser's window object displays an alert dialog box with method alert. Method alert requires as its argument the string to display.
/ 2512 The title bar of the dialog contains the string Microsoft Internet Explorer, to indicate that the browser is presenting a message to the user. Dialog boxes display plain text, they dont render HTML. The alert dialog contains three lines of plain text.
/ 2513 Normally the characters in a string are displayed exactly as they appear between the double quotes. When a backslash is encountered in a string of characters, the next character is combined with the backslash to form an escape sequence. The escape sequence \n is the newline character. It causes the cursor in the HTML document to move to the beginning of the next line in the dialog box.
/ 2514 Escape Characters \n New line \t Horizontal tab \r Carriage Return, any characters output after the carriage return overwrite the previous characters output on that line. \\ Backslash \ Double quote. e.g. window.alert(\in quotes\); \ Single quote. e.g. window.alert(\in quotes\ );
/ 2515 \n, \t and \r do not affect HTML rendering unless they are in a PRE element (this element displays the text between its tags in a fixed-width font exactly as it is formatted between the tags). The other escape sequences result in characters that will be displayed in plain text dialog boxes and in HTML.
/ 2516 The keyword var is used to declare the names of variables. A variable is a location in the computers memory where a value can be stored for use by a program. Though not required, all variable should be declared with a name in a var statement before they are used in a program. A variable name can be any valid identifier. An identifier is a series of characters consisting of letter, digits, underscores ( _ ) and dollar signs ($) that does not begin with a digit and does not contain any spaces.
/ 2517 Declarations end with a semicolon (; ) and can be split over several lines with each variable in the declaration separated by a comma (a comma-separated list of variable names). Several variables may be declared in one declaration or in multiple declarations.
/ 2519 Multiple-line comments begin with delimiter /* and end with delimiter */. All text between the delimiters of the comment is ignored by the compiler. The window object's prompt method displays a dialog into which the user can type a value. The first argument is a message (called a prompt) that directs the user to take a specific action. The optional second argument is the default string to display in the text field.
/ 2521 Variable names correspond to locations in the computer's memory. Every variable has a name, a type size and a value. When a value is placed in a memory location, this value replaces the previous value in that location when a value is read out of a memory location, the process is nondestructive. The arithmetic operators are binary operators because they each operate on two operands.
/ 2522 Operators in arithmetic expressions are applied in a precise sequence determined by the rules of operator precedence. ( ) left to right *, / or % left to right + or – left to right >= left to right = = != left to right =right to left Parentheses may be used to force the order of evaluation of operators to occur in any sequence desired by the programmer.
/ 2523 Parentheses are evaluated first. If they are nested, the expression in the innermost pair is evaluated first. If there are several pairs of parentheses on the same level not nested, they are evaluated left to right. When we say operators are applied from left to right, we are referring to the associativity of the operator. Some operators associate from right to left.
/ 2524 Javas if structure allows a program to make a decision based on the truth or falsity of a condition. If the condition is met (the condition is true), the statement in the body of the if structure is executed. If the condition is not met (the condition is false), the body statement is not executed. Conditions in if structures can be formed by using the equality operators and relational operators.