Archive for August, 2007

CD-91Chapter 10 .Strings, Math, and Dates var msg (Web site optimization)

Wednesday, August 22nd, 2007

CD-91Chapter 10 .Strings, Math, and Dates var msg = Four score msg += and seven msg += years ago, You can also combine the operators if the need arises: var msg = Four score msg += and seven + years ago I use the add-by-value operator a lot when accumulating HTML text to be written to the current document or another window. String methods Of all the core JavaScript objects, the Stringobject has the most diverse collection of methods associated with it. Many methods are designed to help scripts extract segments of a string. Another group, rarely used in my experience, wraps a string with one of several style-oriented tags (a scripted equivalent of tags for font size, style, and the like). To use a string method, the string being acted upon becomes part of the reference followed by the method name. All methods return a value of some kind. Most of the time, the returned value is a converted version of the string object referred to in the method call but the original string is still intact. To capture the modified version, you need to assign the results of the method to a variable: var result = string.methodName() The following sections introduce you to several important string methods available to all browser brands and versions. Changing string case Two methods convert a string to all uppercase or lowercase letters: var result = string.toUpperCase() var result = string.toLowerCase() Not surprisingly, you must observe the case of each letter of the method names if you want them to work. These methods come in handy when your scripts need to compare strings that may not have the same case (for example, a string in a lookup table compared with a string typed by a user). Because the methods don t change the original strings attached to the expressions, you can simply compare the evaluated results of the methods: var foundMatch = false if (stringA.toUpperCase() == stringB.toUpperCase()) { foundMatch = true } String searches You can use the string.indexOf() method to determine if one string is contained by another. Even within JavaScript s own object data, this can be useful information. For example, another property of the navigatorobject in Chapter 3 (navigator.userAgent) reveals a lot about the browser that loads the page. A script can investigate the value of that property for the existence of, say, Win to determine that the user has a Windows operating system. That short string might
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

CD-90 Part II . JavaScript Tutorial String Objects (Free php web host)

Tuesday, August 21st, 2007

CD-90 Part II . JavaScript Tutorial String Objects You have already used String objects many times in earlier lessons. A string is any text inside a quote pair. A quote pair consists of either double quotes or single quotes. This allows one string to nest inside another, as often happens in event handlers. In the following example, the alert()method requires a quoted string as a parameter, but the entire method call also must be inside quotes. onClick= alert( Hello, all ) JavaScript imposes no practical limit on the number of characters that a string can hold. However, most older browsers have a limit of 255 characters in length for a script statement. This limit is sometimes exceeded when a script includes a lengthy string that is to become scripted content in a page. You need to divide such lines into smaller chunks using techniques described in a moment. You have two ways to assign a string value to a variable. The simplest is a basic assignment statement: var myString = Howdy This works perfectly well except in some exceedingly rare instances. Beginning with Navigator 3 and Internet Explorer 4, you can also create a string object using the more formal syntax that involves the newkeyword and a constructor function (that is, it constructs a new object): var myString = new String( Howdy ) Whichever way you use to initialize a variable with a string, the variable receiving the assignment can respond to all Stringobject methods. Joining strings Bringing two strings together as a single string is called concatenating strings, a term you learned in Chapter 6. String concatenation requires one of two JavaScript operators. Even in your first script in Chapter 3, you saw how the addition operator (+) linked multiple strings together to produce the text dynamically written to the loading Web page: document.write( of + navigator.appName + . ) As valuable as that operator is, another operator can be even more scripter friendly. This operator is helpful when you are assembling large strings in a single variable. The strings may be so long or cumbersome that you need to divide the building process into multiple statements. The pieces may be combinations of string literals (strings inside quotes) or variable values. The clumsy way to do it (perfectly doable in JavaScript) is to use the addition operator to append more text to the existing chunk: var msg = Four score msg = msg + and seven msg = msg + years ago, But another operator, called the add-by-value operator, offers a handy shortcut. The symbol for the operator is a plus and equal sign together (+=). This operator means append the stuff on the right of me to the end of the stuff on the left of me. Therefore, the preceding sequence is shortened as follows:
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Strings, Math, 10and Dates CHAPTER …. For most (Web server address)

Tuesday, August 21st, 2007

Strings, Math, 10and Dates CHAPTER …. For most of the lessons in the tutorial so far, the objects at the center of attention belong to the document object model. But as indicated in Chapter 2, a clear dividing line exists between the document object model and the JavaScript language. The language has some of its own objects that are independent of the document object model. These objects are defined such that if a vendor wished to implement JavaScript as the programming language for an entirely different kind of product, the language would still use these core facilities for handling text, advanced math (beyond simple arithmetic), and dates. You can find formal specifications of these objects in the ECMA-262 recommendation. Core Language Objects It is often difficult for newcomers to programming or even experienced programmers who have not worked in object-oriented worlds before to think about objects, especially when attributed to things that don t seem to have a physical presence. For example, it doesn t require lengthy study to grasp the notion that a button on a page is an object. It has several physical properties that make perfect sense. But what about a string of characters? As you learn in this chap ter, in an object-based environment such as JavaScript, every thing that moves is treated as an object each piece of data from a Boolean value to a date. Each such object probably has one or more properties that help define the content; such an object may also have methods associated with it to define what the object can do or what you can do to the object. I call all objects that are not part of the document object model core language objects. You can see the full complement of them in the Quick Reference in Appendix A. In this chapter, I focus on the String, Math, and Dateobjects. In This Chapter How to modify strings with common string methods When and how to use the Math object How to use the Date object ….
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

My space web page - CD-87Chapter 9 .Forms and Form Elements One quirky

Monday, August 20th, 2007

CD-87Chapter 9 .Forms and Form Elements One quirky bit of behavior involving the submit() method and onSubmit event handler needs explanation. While you might think (and logically so, in my opinion) that the submit() method would be the exact scripted equivalent of a click of a real Submit button, it s not. In Navigator, the submit() method does not cause the form s onSubmit event handler to fire at all. If you want to perform validation on a form submitted via the submit()method, invoke the validation in the script func tion that ultimately calls the submit() method. So much for the basics of forms and form elements. In the next chapter, you step away from HTML for a moment to look at more advanced JavaScript core language items: strings, math, and dates. Exercises 1. Rework Listings 9-1, 9-2, 9-3, and 9-4 so that the script functions all receive the most efficient form or form element references from the invoking event handler. 2. Modify Listing 9-6 so that instead of the Submit button making the submission, the submission is performed from a hyperlink. Be sure to include the form validation in the process. 3. In the following HTML tag, what kind of information do you think is being passed with the event handler? Write a function that displays in an alert dialog box the information being passed. 4. A document contains two forms named specificationsand accessories. In the accessories form is a field named acc1. Write two different statements that set the contents of that field to Leather Carrying Case. 5. Create a page that includes a SELECT object to change the background color of the current page. The property that you need to set is document.bgColor, and the three values you should offer as options are red, yellow, and green. In the SELECT object, the colors should display as Stop, Caution, and Go. Note: If you use a Macintosh or UNIX version of Navigator, you must employ version 4 or later for this exercise. …
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

1 on 1 web hosting - CD-86 Part II . JavaScript Tutorial Before a

Monday, August 20th, 2007

CD-86 Part II . JavaScript Tutorial Before a form is submitted, you may wish to perform some last-second validation of data in the form or in other scripting (for example, changing the form s action property based on user choices). You can do this in a function invoked by the form s onSubmit event handler. Specific validation routines are beyond the scope of this tutorial (but are explained in substantial detail in Chapter 43), but I want to show you how the onSubmit event handler works. In all but the first generation of scriptable browsers from Microsoft (IE3) and Netscape (NN2), you can let the results of a validation function cancel a submission if the validation shows some incorrect data or empty fields. To control submission, the onSubmit event handler must evaluate to returntrue (to allow submission to continue) or returnfalse(to cancel submission). This is a bit tricky at first because it involves more than just having the function called by the event handler return trueor false. The return keyword must be part of the final evaluation. Listing 9-6 shows a page with a simple validation routine that ensures all fields have something in them before allowing submission to continue. (The form has no ACTION attribute, so this sample form doesn t get sent to the server.) Notice how the onSubmit event handler (which passes a reference to the FORM object as a parameter in this case the thiskeyword points to the FORM object because its tag holds the event handler) includes the returnkeyword before the function name. When the function returns its trueor false value, the event handler evaluates to the requisite returntrue or returnfalse. Listing 9-6: Last-Minute Checking Before Form Submission Validator

Please enter all requested information:
First Name:
Last Name:
Rank:
Serial Number:

We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Web hosting resellers - CD-85Chapter 9 .Forms and Form Elements // assign

Sunday, August 19th, 2007

CD-85Chapter 9 .Forms and Form Elements // assign values to variables for convenience var beatle = form.Beatles[i].value var song = form.song.value alert( Checking whether + song + features + beatle + … ) } function verifySong(entry) { var song = entry.value alert( Checking whether + song + is a Beatles tune… ) }

Choose your favorite Beatle: John Paul George Ringo

Enter the name of your favorite Beatles song:

Get to know the usage of the this keyword in passing form and form element objects to functions. The technique not only saves you typing in your code, but it also ensures accuracy in references to those objects. Submitting and Prevalidating Forms If you have worked with Web pages and forms before, you are familiar with how simple it is to add a Submit-style button that sends the form to your server. However, design goals for your page may rule out the use of ugly system-generated buttons. If you d rather display a pretty image, the link tag surrounding that image should use the javascript: URL technique to invoke a script that submits the form (the image type of INPUTelement is not recognized prior to IE4 and NN6). The scripted equivalent of submitting a form is the FORM object s submit() method. All you need in the statement is a reference to the form and this method: document.forms[0].submit() One limitation might inhibit your plans to secretly have a script send you an e-mail message from every visitor who comes to your Web site. If the form s ACTION attribute is set to a mailTo: URL, JavaScript does not pass along the submit() method to the form. See Chapter 23 for cautions about using the mailTo:URL as a form s action.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

CD-84 Part II . JavaScript Tutorial handler for (Managed web hosting)

Sunday, August 19th, 2007

CD-84 Part II . JavaScript Tutorial handler for a text field, you can pass a reference to the text object to the function by inserting the thiskeyword as a parameter to the function: At the receiving end, the function defines a parameter variable that turns that reference into a variable that the rest of the function can use: function upperMe(field) { statement[s] } The name you assign to the function s parameter variable is purely arbitrary, but it is helpful to give it a name that expresses what the reference is. Importantly, this reference is a live connection back to the object. Therefore, statements in the script can get and set property values of the object at will. For other functions, you may wish to receive a reference to the entire form, rather than just the object calling the function. This is certainly true if the function needs to access other elements of the same form. To pass the entire form, you reference the formproperty of the INPUT object, still using the this keyword: The function definition should then have a parameter variable ready to be assigned to the form object reference. Again, you decide the name of the variable. I tend to use the variable name formas a way to remind me exactly what kind of object is referenced. function inspect(form) { statement[s] } Listing 9-5 demonstrates passing both an individual form element and the entire form in the performance of two separate acts. This page makes believe it is con nected to a database of Beatles songs. When you click the Process Data button, it passes the form object, which the processData()function uses to access the group of radio buttons inside a for loop. Additional references using the passed form object extract the valueproperties of the selected radio button and the text field. The text field has its own event handler, which passes just the text field to the verifySong() function. Notice how short the reference is to reach the value property of the song field inside the function. Listing 9-5: Passing a Form Object and Form Element to Functions Beatle Picker

Choose a place to go:
Note Internet Explorer and NN6 expose the value property of the selected option item as the value property of the SELECT object. While this is certainly a logical and convenient shortcut, for compatibility reasons you should use the long way shown in Listing 9-4. There is much more to the SELECT object, including the ability to change the contents of a list in newer browsers. Chapter 26 covers the object in depth. Passing Form Data and Elements to Functions In all of the examples so far in this lesson, when an event handler invokes a func tion that works with form elements, the form or form element is explicitly refer enced in the function. But valuable shortcuts do exist for transferring information about the form or form control directly to the function without dealing with those typically long references that start with the window or document object level. JavaScript features a keyword this that always refers to whatever object contains the script in which the keyword is used. Thus, in an onChangeevent
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

CD-82 Part II . JavaScript Tutorial The SELECT (Web host music)

Saturday, August 18th, 2007

CD-82 Part II . JavaScript Tutorial The SELECT Object The most complex form element to script is the SELECT element object. As you can see from the lowest common denominator object hierarchy diagram (Figures 4-6 or 8-1), the SELECT object is really a compound object: an object that contains an array of OPTION objects. Moreover, you can establish this object in HTML to display itself as either a pop-up list or a scrolling list the latter configurable to accept multiple selections by users. For the sake of simplicity at this stage, this lesson focuses on deployment as a pop-up list that allows only single selections. Some properties belong to the entire SELECT object; others belong to individual options inside the SELECT object. If your goal is to determine which item the user selects, you must use properties of both the SELECT and OPTION objects. The most important property of the SELECT object itself is the selectedIndex property, accessed as follows: document.form[0].selectName.selectedIndex This value is the index number of the currently selected item. As with most index counting schemes in JavaScript, the first item (the one at the top of the list) has an index of zero. The selectedIndex value is critical for enabling you to access properties of the selected option. Two important properties of an option item are text and value, accessed as follows: document.forms[0].selectName.options[n].text document.forms[0].selectName.options[n].value The text property is the string that appears onscreen in the SELECT object. It is unusual for this information to be exposed as a FORM object property because in the HTML that generates a SELECT object, the text is defined outside of the

Web hosting support - CD-81Chapter 9 .Forms and Form Elements Listing 9-3

Saturday, August 18th, 2007

CD-81Chapter 9 .Forms and Form Elements Listing 9-3 demonstrates several aspects of the radio button object, including how to look through a group of buttons to find out which one is checked and how to use the VALUEattribute and corresponding property for meaningful work. The page includes three radio buttons and a plain button. Each radio button s VALUE attribute contains the full name of one of the Three Stooges. When the user clicks the button, the onClick event handler invokes the fullName() function. In that function, the first statement creates a shortcut reference to the form. Next, a for repeat loop looks through all of the buttons in the stooges radio button group. An if construction looks at the checked property of each button. When a button is highlighted, the break statement bails out of the forloop, leaving the value of the i loop counter at the number where the loop broke ranks. The alert dialog box then uses a reference to the value property of the ith button so that the full name can be displayed in the alert. Listing 9-3: Scripting a Group of Radio Objects Extracting Highlighted Radio Button

Select your favorite Stooge: Moe Larry Curly
As you learn about form elements in later chapters of this book, the browser s tendency to create arrays out of identically named objects of the same type (except for Internet Explorer 3) can be a benefit to scripts that work with, say, columns of fields in an HTML order form.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.