Archive for April, 2007

Cedant web hosting - 75Chapter 7Programming Fundamentals, Part IIvariables or they become

Wednesday, April 25th, 2007

75Chapter 7Programming Fundamentals, Part IIvariables or they become recognized as global variables). The scope of a local variable isonly within the statements of the function. No other functions or statements outside of func- tions have access to a local variable. Local scopeallows for the reuse of variable names within a document. For most variables, Istrongly discourage this practice because it leads to confusion and bugs that are difficult totrack down. At the same time, it is convenient to reuse certain kinds of variable names, suchas forloop counters. These are safe because they are always reinitialized with a startingvalue whenever a forloop starts. You cannot, however, nest one forloop inside anotherwithout specifying a different loop counting variable in the nested loop. To demonstrate the structure and behavior of global and local variables and show you whyyou shouldn t reuse most variable names inside a document Listing 7-2 defines two globaland two local variables. I intentionally use bad form by initializing a local variable that hasthe same name as a global variable. Listing 7-2:Global and Local Variable Scope Demonstration When the page loads, the script in the Head portion initializes the two global variables (aBoyand hisDog) and defines the demo()function in memory. In the Body, another script beginsby invoking the function. Inside the function, a local variable is initialized with the same nameas one of the global variables hisDog. In JavaScript, such a local initialization overrides theglobal variable for all statements inside the function. (But note that if the varkeyword is leftoff of the local initialization, the statement reassigns the value of the global version to Gromit. ) Another local variable, output, is merely a repository for accumulating the text that is to bewritten to the screen. The accumulation begins by evaluating the local version of the hisDogvariable. Then it concatenates some hard-wired text (note the extra spaces at the edges ofthe string segment). Next comes the evaluated value of the aBoyglobal variable any global
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

Web hosting india - 74Part IIJavaScript TutorialParameters (also known as arguments) provide

Wednesday, April 25th, 2007

74Part IIJavaScript TutorialParameters (also known as arguments) provide a mechanism for handing off a value fromone statement to another by way of a function call. If no parameters occur in the function def- inition, both the function definition and call to the function have only empty sets of parenthe- ses (as shown in Chapter 5, Listing 5-8). When a function receives parameters, it assigns the incoming values to the variable namesspecified in the function definition s parentheses. Consider the following script segment: function sayHiToFirst(a, b, c) { alert( Say hello, + a); } sayHiToFirst( Gracie , George , Harry ); sayHiToFirst( Larry , Moe , Curly ); After the function is defined in the script, the next statement calls that very function, passingthree strings as parameters. The function definition automatically assigns the strings to vari- ables a, b, and c. Therefore, before the alert()statement inside the function ever runs, aevaluates to Gracie, bevaluates to George, and cevaluates to Harry. In the alert() statement, only the avalue is used and the alert readsSay hello, GracieWhen the user closes the first alert, the next call to the function occurs. This time through, different values are passed to the function and assigned to a, b, and c. The alert dialog boxreadsSay hello, LarryUnlike other variables that you define in your script, function parameters do not use the varkeyword to initialize them. They are automatically initialized whenever the function is called. Variable scopeSpeaking of variables, it s time to distinguish between variables that are defined outside andthose defined inside of functions. Variables defined outside of functions are called global vari- ables; those defined inside functions with the varkeyword are called local variables. A global variable has a slightly different connotation in JavaScript than it has in most otherlanguages. For a JavaScript script, the globe of a global variable is the current documentloaded in a browser window or frame. Therefore, when you initialize a variable as a globalvariable, it means that all script statements in the page (including those inside functions) have direct access to that variable value. Statements can retrieve and modify global variablesfrom anywhere in the page. In programming terminology, this kind of variable is said to haveglobal scopebecause everything on the page can see it. It is important to remember that the instant a page unloads itself, all global variables definedin that page disappear from memory forever. If you need a value to persist from one page toanother, you must use other techniques to store that value (for example, as a global variablein a framesetting document, as described in Chapter 16; or in a cookie, as described inChapter 18). While the varkeyword is usually optional for initializing global variables, Istrongly recommend you use it for all variable initializations to guard against future changesto the JavaScript language. In contrast to the global variable, a local variable is defined inside a function. You already sawhow parameter variables are defined inside functions (without varkeyword initializations). But you can also define other variables with the varkeyword (absolutely required for local
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision mysql hosting services

Msn web hosting - 73Chapter 7Programming Fundamentals, Part IIclassification of routine exists

Tuesday, April 24th, 2007

73Chapter 7Programming Fundamentals, Part IIclassification of routine exists for JavaScript. A function is capable of returning a value to thestatement that invoked it, but this is not a requirement. However, when a function doesreturn a value, the calling statement treats the function call like any expression plugging inthe returned value right where the function call is made. I will show some examples in amoment. Formal syntax for a function is as follows: function functionName( [parameter1]…[,parameterN] ) { statement[s] } Names you assign to functions have the same restrictions as names you assign to HTML ele- ments and variables. You should devise a name that succinctly describes what the functiondoes. I tend to use multiword names with the interCap (internally capitalized) format thatstart with a verb because functions are action items, even if they do nothing more than get orset a value. Another practice to keep in mind as you start to create functions is to keep the focus of eachfunction as narrow as possible. It is possible to generate functions that are literally hundredsof lines long. Such functions are usually difficult to maintain and debug. Chances are that youcan divide the long function into smaller, more tightly focused segments. Function parametersIn Chapter 5, you saw how an event handler invokes a function by calling the function byname. Any call to a function, including one that comes from another JavaScript statement, works the same way: a set of parentheses follows the function name. You also can define functions so they receive parameter values from the calling statement. Listing 7-1 shows a simple document that has a button whose onclickevent handler calls afunction while passing text data to the function. The text string in the event handler call is ina nested string a set of single quotes inside the double quotes required for the entire eventhandler attribute. Listing 7-1:Calling a Function from an Event Handler


Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services

72Part IIJavaScript TutorialA repeat looplets a script cycle (Make a web site)

Tuesday, April 24th, 2007

72Part IIJavaScript TutorialA repeat looplets a script cycle through a sequence of statements until some condition ismet. For example, a JavaScript data validation routine might inspect every character that youenter into a form text field to make sure that each one is a number. Or if you have a collectionof data stored in a list, the loop can check whether an entered value is in that list. Once thatcondition is met, the script can then break out of the loop and continue with the next state- ment after the loop construction. The most common repeat loop construction used in JavaScript is called the forloop. It getsits name from the keyword that begins the construction. A forloop is a powerful devicebecause you can set it up to keep track of the number of times the loop repeats itself. The for- mal syntax of the forloop is as follows: for ([initial expression]; [condition]; [update expression]) { statement[s] inside loop} The square brackets mean that the item is optional. However, until you get to know the forloop better, I recommend designing your loops to utilize all three items inside the parenthe- ses. The initial expressionportion usually sets the starting value of a counter variable. Thecondition the same kind of condition you saw for ifconstructions defines the conditionthat forces the loop to stop going around and around. Finally, the update expressionis a state- ment that executes each time all of the statements nested inside the construction completerunning. A common implementation initializes a counting variable, i, increments the value of iby oneeach time through the loop, and repeats the loop until the value of iexceeds some maximumvalue, as in the following: for (var i = startValue; i <= maxValue; i++) { statement[s] inside loop} Placeholders startValueand maxValuerepresent any numeric values, including explicitnumbers or variables holding numbers. In the update expression is an operator you have notseen yet. The ++operator adds 1 to the value of ieach time the update expression runs atthe end of the loop. If startValueis 1, the value of iis 1 the first time through the loop, 2the second time through, and so on. Therefore, if maxValueis 10, the loop repeats itself 10times (in other words, as long as iis less than or equal to 10). Generally speaking, the state- ments inside the loop use the value of the counting variable in their execution. Later in thislesson, I show how the variable can play a key role in the statements inside a loop. At thesame time, you will see how to break out of a loop prematurely and why you may need to dothis in a script. FunctionsIn Chapter 5, you saw a preview of the JavaScript function. A functionis a definition of a set ofdeferred actions. Functions are invoked by event handlers or by statements elsewhere in thescript. Whenever possible, good functions are designed for reuse in other documents. Theycan become building blocks you use over and over again. If you have programmed before, you can see parallels between JavaScript functions and otherlanguages subroutines. But unlike some languages that distinguish between procedures(which carry out actions) and functions (which carry out actions and return values), only one
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision mysql5 web hosting services

Sri lanka web server - 71Chapter 7Programming Fundamentals, Part IIIn this example, the

Tuesday, April 24th, 2007

71Chapter 7Programming Fundamentals, Part IIIn this example, the data type of the value inside myAgemust be a number so that the propercomparison (via the Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services

70Part IIJavaScript TutorialIn your trip to the (Yahoo free web hosting) store,

Tuesday, April 24th, 2007

70Part IIJavaScript TutorialIn your trip to the store, you go through the same kinds of decisions and repetitions that yourJavaScript programs also encounter. If you understand these frameworks in real life, you cannow look into the JavaScript equivalents and the syntax required to make them work. Control StructuresIn the vernacular of programming, the kinds of statements that make decisions and looparound to repeat themselves are called control structures. A control structure directs the exe- cution flow through a sequence of script statements based on simple decisions and otherfactors. An important part of a control structure is the condition. Just as you may travel differentroutes to work depending on certain conditions (for example, nice weather, nighttime, attend- ing a soccer game), so, too, does a program sometimes have to branch to an execution routeif a certain condition exists. Each condition is an expression that evaluates to trueorfalse one of those Boolean data types mentioned in Chapter 6. The kinds of expressionscommonly used for conditions are expressions that include a comparison operator. You dothe same in real life: If it is true that the outdoor temperature is less than freezing, you put ona coat before going outside. In programming, however, the comparisons are strictly compar- isons of values. JavaScript provides several kinds of control structures for different programming situations. Three of the most common control structures you ll use are ifconstructions, if…elseconstructions, and forloops. Chapter 31 covers in great detail other common control structures you should know. For thistutorial, however, you need to learn about the three common ones just mentioned. if constructionsThe simplest program decision is to follow a special branch or path of the program if a cer- tain condition is true. Formal syntax for this construction follows. Items in italics get replacedin a real script with expressions and statements that fit the situation. if (condition) { statement[s] if true} Don t worry about the curly braces yet. Instead, get a feel for the basic structure. The key- word, if, is a must. In the parentheses goes an expression that evaluates to a Boolean value. This is the condition being tested as the program runs past this point. If the condition evalu- ates to true, one or more statements inside the curly braces execute before continuing onwith the next statement after the closing brace. If the condition evaluates to false, the state- ments inside the curly braces are ignored and processing continues with the next statementafter the closing brace. The following example assumes that a variable, myAge, has had its value set earlier in thescript (exactly how is not important for this example). The condition expression comparesthe value myAgeagainst a numeric value of 18. if (myAge < 18) { alert( Sorry, you cannot vote. ); }
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision virtual web hosting services

Sex offenders web site - ProgrammingFundamentals, PartIIYour tour of programming fundamentals continues in

Monday, April 23rd, 2007

ProgrammingFundamentals, PartIIYour tour of programming fundamentals continues in this chapterwith subjects that have more intriguing possibilities. For exam- ple, I show you how programs make decisions and why a programmust sometimes repeat statements over and over. Before you re fin- ished here, you will learn how to use one of the most powerful infor- mation holders in the JavaScript language: the array. Decisions and LoopsEvery waking hour of every day you make decisions of some kind most of the time you probably don t even realize it. Don t think so? Well, look at the number of decisions you make at the grocery store, from the moment you enter the store to the moment you clear thecheckout aisle. No sooner do you enter the store than you are faced with a decision. Based on the number and size of items you intend to buy, do you pickup a hand-carried basket or attempt to extricate a shopping cart fromthe metallic conga line near the front of the store? That key decisionmay have impact later when you see a special offer on an item that istoo heavy to put into the hand basket. Next, you head for the food aisles. Before entering an aisle, you com- pare the range of goods stocked in that aisle against items on yourshopping list. If an item you need is likely to be found in this aisle, you turn into the aisle and start looking for the item; otherwise, youskip the aisle and move to the head of the next aisle. Later, you reach the produce section in search of a juicy tomato. Standing in front of the bin of tomatoes, you begin inspecting themone by one picking one up, feeling its firmness, checking the color, looking for blemishes or signs of pests. You discard one, pick upanother, and continue this process until one matches the criteria youset in your mind for an acceptable morsel. Your last stop in the storeis the checkout aisle. Paper or plastic? the clerk asks. One moredecision to make. What you choose impacts how you get the gro- ceries from the car to the kitchen as well as your recycling habits. 77CHAPTER …In This ChapterHow control structuresmake decisionsHow to define functionsWhere to initializevariables efficientlyWhat those darnedcurly braces are allaboutThe basics of dataarrays …
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision ftp web hosting services

68Part IIJavaScript TutorialListing 6-1:What s Wrong with This Page? (Abyss web server)

Monday, April 23rd, 2007

68Part IIJavaScript TutorialListing 6-1:What s Wrong with This Page?


____________

5.What does the term concatenatemean in the context of JavaScript programming? …
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services

Photoshop web design - 67Chapter 6Programming Fundamentals, Part ITable 6-2: JavaScript Comparison

Monday, April 23rd, 2007

67Chapter 6Programming Fundamentals, Part ITable 6-2: JavaScript Comparison OperatorsSymbolDescription==Equals!=Does not equal>Is greater than>=Is greater than or equal toNote: If you are looking for high quality webhost to host and run your jsp application check Vision florida web design services

66Part IIJavaScript (Web hosting reviews) Tutorialwith an expression containing mixed data

Sunday, April 22nd, 2007

66Part IIJavaScript Tutorialwith an expression containing mixed data types. Even so, it is good practice to perform datatype conversions explicitly in your code to prevent any potential ambiguity. The simplest wayto convert a number to a string is to take advantage of JavaScript s string tendencies in addi- tion operations. By adding an empty string to a number, you convert the number to its stringequivalent: ( + 2500) // result = 2500 ( + 2500).length // result = 4In the second example, you can see the power of expression evaluation at work. The paren- theses force the conversion of the number to a string. A stringis a JavaScript object that hasproperties associated with it. One of those properties is the lengthproperty, which evalu- ates to the number of characters in the string. Therefore, the length of the string 2500 is 4. Note that the length value is a number, not a string. OperatorsYou will use lots of operatorsin expressions. Earlier, you used the equal sign (=) as an assign- ment operator to assign a value to a variable. In the preceding examples with strings, youused the plus symbol (+) to join two strings. An operator generally performs some kind of cal- culation (operation) or comparison with two values (the value on each side of an operator iscalled an operand) to reach a third value. In this lesson, I briefly describe two categories ofoperators arithmetic and comparison. Chapter 32 covers many more operators, but onceyou understand the basics here, the others are easier to grasp. Arithmetic operatorsIt may seem odd to talk about text strings in the context of arithmetic operators, but youhave already seen the special case of the plus (+) operator when one or more of the operandsis a string. The plus operator instructs JavaScript to concatenate(pronounced kon-KAT-en- eight), or join, two strings together precisely where you place the operator. The string con- catenation operator doesn t know about words and spaces, so the programmer must makesure that any two strings to be joined have the proper word spacing as part of the strings even if that means adding a space: firstName = John ; lastName = Doe ; fullName = firstName + + lastName; JavaScript uses the same plus operator for arithmetic addition. When both operands arenumbers, JavaScript knows to treat the expression as an arithmetic addition rather than astring concatenation. The standard math operators for addition, subtraction, multiplication, and division (+, -, *, /) are built into JavaScript. Comparison operatorsAnother category of operator helps you compare values in scripts whether two values arethe same, for example. These kinds of comparisons return a value of the Boolean type trueor false. Table 6-2 lists the comparison operators. The operator that tests whether twoitems are equal consists of a pair of equal signs to distinguish it from the single equal signassignment operator.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services