Archive for August, 2007

535Chapter 23 .The Form and Related Objects Tip (Free web space)

Friday, August 31st, 2007

535Chapter 23 .The Form and Related Objects Tip The best opportunity to change the properties of a FORM element object is in a function invoked by the form s onSubmit event handler. The modifications are performed at the last instant prior to actual submission, leaving no room for user- induced glitches to get in the way. Buttons in forms A common mistake that newcomers to scripting make is defining all clickable buttons as the submit type of inputobject (). The Submit button does exactly what it says it submits the form. If you don t set any METHOD or ACTION attributes of the

tag, the browser inserts its default values for you: METHOD=GETand ACTION=pageURL. When you submit a form with these attributes, the page reloads itself and resets all field values to their initial values. Use a Submit button only when you want the button to actually submit the form. If you want a button for other types of action, use the button style (). A regular button can invoke a function that performs some internal actions and then invokes the FORM element object s submit() method to submit the form under script control. Redirection after submission Undoubtedly, you have submitted a form to a site and seen a Thank You page come back from the server to verify that your submission was accepted. This is warm and fuzzy, if not logical, feedback for the submission action. It is not surprising that you would want to recreate that effect even if the submission is to a mailto: URL. Unfortunately, a problem gets in the way. A common sense approach to the situation calls for a script to perform the submission (via the form.submit() method) and then navigate to another page that does the Thank You. Here is such a scenario from inside a function triggered by a click of a link surrounding a nice, graphical Submit button: function doSubmit() { document.forms[0].submit() location.href = thanks.html } The problem is that when another statement executes immediately after the form.submit() method, the submission is canceled. In other words, the script does not wait for the submission to complete itself and verify to the browser that all is well (even though the browser appears to know how to track that information given the statusbar feedback during submission). The point is, because JavaScript does not provide an event that is triggered by a successful submission, there is no sure-fire way to display your own Thank You page. Don t be tempted by the window.setTimeout() method to change the location after some number of milliseconds following the form.submit() method. You cannot predict how fast the network and/or server is for every visitor. If the submission does not complete before the timeout ends, then the submission is still canceled even if it is partially complete. It s too bad we don t have this power at our disposal yet. Perhaps a future version of the document object model will provide an event that enables us to do something only after a successful submission. FORM
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

534 Part III . Document Objects Reference Many (Adelphia web hosting)

Friday, August 31st, 2007

534 Part III . Document Objects Reference Many ISPs that host Web sites provide standard CGIs for forwarding forms to an e-mail address of your choice. This manner of capturing form data, however, does not also capture the visitor s e-mail address unless your form has a field where the visitor voluntarily enters that information. Note Under no circumstances is a form submitted via the mailto: URL a secure document. The form data is embedded within a plain e-mail message that goes through the same Internet routes and servers as any e-mail message. The remaining discussion about mailing forms focuses primarily on NN2+ and IE5+ browsers. You should be aware that mailing forms in the following ways is controversial in some Web standards circles. As of this writing, the W3C HTML specification does not endorse these techniques specifically. However, the latest browsers do support them nonetheless. Use these facilities judiciously and only after extensive testing on the client browsers you intend to support. If you want to have forms submitted as e-mail messages, you must attend to three tag attributes. The first is the METHODattribute. You must set it to POST. Next comes ENCTYPE. If you omit this attribute, the e-mail client sends the form data as an attachment consisting of escaped name-value pairs, as in this example: name=Danny+Goodman&rank=Scripter+First+Class&serialNumber=042 But if you set the ENCTYPE attribute to text/plain, the form name-value pairs are placed in the body of the mail message in a more human-readable format: name=Danny Goodman rank=Scripter First Class serialNumber=042 The last attribute of note is the ACTION attribute, which is normally the spot to place a URL to another file or server CGI. Substitute the URL with the special mailto:URL followed by an optional parameter for the subject. Here is an example: ACTION= mailto:prez@whitehouse.gov?subject=Opinion%20Poll To sum up, the following example shows the complete tag for e-mailing the form in Navigator. None of this requires any JavaScript at all. But seeing how you can use the attributes and the fact that these attributes are exposed as properties of the FORM element object you might see some extended possibilities for script control over forms. Changing form attributes With the exception of IE3 (whose FORM object properties are read-only), all scriptable browsers expose FORM element attributes as modifiable properties. Therefore, you can change, say, the action of a form via a script in response to user interaction on your page. For example, you can have two different CGI programs invoked on your server depending on whether a form s checkbox is checked. FORM
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Web host music - 533Chapter 23 .The Form and Related Objects Tip

Thursday, August 30th, 2007

533Chapter 23 .The Form and Related Objects Tip a live connection with its object. To modify a property of the object that invokes an event handler function, you need to pass some object reference so that the function knows where to go to work on the object. Many programmers with experience in other languages expect parameters to be passed either by reference or by value, but not both ways. The rule of thumb in JavaScript, however, is fairly simple: object references are passed by reference; property values are passed by value. Here are some guidelines to follow when deciding what kind of value to pass to an event handler function: . Pass the entire form control object (this) when the function needs to make subsequent access to that same element (perhaps reading an object s value property, converting the value to all uppercase letters, and then writing the result back to the same object s value property). . Pass only one property (this.propertyName) when the function needs read- only access to that property. . Pass the entire FORM element object (this.form) for the function to access multiple elements inside a form (for example, a button click means that the function must retrieve a field s content). Also be aware that you can submit multiple parameters (for example, onClick= someFunction (this.form, this.name) ) or even an entirely different object from the same form (for example, onClick= someFunction (this.form.emailAddr.value) ). Simply adjust your function s incoming parameters accordingly. (See Chapter 41 for more details about custom functions.) E-mailing forms A common request among scripters is how to send a form via e-mail to the page s author. This includes the occasional desire to send secret e-mail to the author whenever someone visits the Web site. Let me address the privacy issue first. A site visitor s e-mail address is valuable personal information that you should not retrieve without the visitor s permission or knowledge. That s one reason why Netscape plugged a privacy hole in Navigator 2 that allowed submitting a form to a mailto: URL without requesting permission from the user. You can use some workarounds for this in Navigator 3, but I do not condone surreptitiously lifting e-mail addresses and therefore choose not to publicize those workarounds here. Besides, as more users gravitate to newer browser versions, the workarounds fail anyway. Microsoft, on the other hand, went too far in preventing forms e-mailing in the earliest browser versions. While Netscape s browsers reveal to the user in an alert that an e-mail message bearing the user s e-mail address (as stored in the browser s preferences) will be sent upon approval, Internet Explorer 3 does not send form content via e-mail at all. Internet Explorer 4 sends form content as an attachment through Microsoft Outlook, but only after displaying a mail composition window to the user. Starting with IE5, the process is much more fluid, but the action works best when Outlook is the default e-mail client on the computer. FORM
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

532 Part III . Document Objects Reference The (Web hosting providers)

Thursday, August 30th, 2007

532 Part III . Document Objects Reference The reference to the form contains everything the browser needs to know to find that form within the document. Any statements in the function can therefore use the parameter value in place of the longer, more cumbersome reference to the form. Thus, here I can use form to take the place of document.forms[0]in any address. To get the value of the song field, the reference is: form.song.value Had I assigned the form object to a parameter variable called sylvester, the reference would have been: sylvester.song.value When a function parameter is a reference to an object, statements in the function can retrieve or set properties of that object as well as invoke the object s methods. Another version of the thisparameter passing style simply uses the word this as the parameter. Unlike this.form, which passes a reference to the entire form connected to a particular element, thispasses a reference only to that one element. In Listing 23-1, you can add an event handler to the songfield to do some validation of the entry (to make sure that the entry appears in a database array of Beatles songs created elsewhere in the document). Therefore, you want to send only the field object to the function for analysis:

You then have to create a function to catch this call: function checkSong(songTitle) { var enteredSong = songTitle.value alert( Making sure that + enteredSong + was recorded by the Beatles. ) } Within this function, you can go straight to the heart the valueproperty of the field element without a long reference. One further extension of this methodology passes only a single property of a form control element as a parameter. In the last example, the checkSong() function needs only the value property of the field, so the event handler can pass this. value as a parameter. Because this refers to the very object in which the event handler appears, the this.propertyNamesyntax enables you to extract and pass along a single property:

A benefit of this way of passing form element data is that the function doesn t have to do as much work: function checkSong(songTitle) { alert( Making sure that + songTitle + was recorded by the Beatles. ) } Unlike passing object references (like the form and text field objects above), when you pass a property value (for example, this.value), the property s value is passed with no reference to the object from which it came. This suffices when the function just needs the value to do its job. However, if part of that job is to modify the object s property (for example, converting all text from a field to uppercase and redisplaying the converted text), the value passed to the function does not maintain FORM
We recommend high quality webhost to host and run your jsp application: christian web host services.

Web server info - 531Chapter 23 .The Form and Related Objects Figure

Thursday, August 30th, 2007

531Chapter 23 .The Form and Related Objects Figure 23-1: Controls pass different object references to functions in Listing 23-1. The processData() function, which needs to read and write properties of multiple form control elements, can reference the controls in two ways. One way is to have the onClickevent handler (in the button element at the bottom of the document) call the processData() function and not pass any parameters. Inside the function, all references to objects (such as the radio buttons or the song field) must be complete references, such as document.forms[0].song.value to retrieve the value entered into the song field. A more efficient way is to send a reference to the FORM object as a parameter with the call to the function (as shown in Listing 23-1). By specifying this.formas the parameter, you tell JavaScript to send along everything it knows about the form from which the function is called. This works because formis a property of every form control element; the property is a reference to the form that contains the control. Therefore, this.form passes the value of the form property of the control. At the function, the reference to the FORM object is assigned to a variable name (arbitrarily set to formhere) that appears in parentheses after the function name. I use the parameter variable name formhere because it represents an entire form. But you can use any valid variable name you like. FORM
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

530 Part III . Document Objects Reference Passing (Make my own web site)

Wednesday, August 29th, 2007

530 Part III . Document Objects Reference Passing forms and elements to functions When a form or form element contains an event handler that calls a function defined elsewhere in the document, you can use a couple of shortcuts to simplify the task of addressing the objects while the function does its work. Failure to grasp this concept not only causes you to write more code than you have to, but it also hopelessly loses you when you try to trace somebody else s code in his or her JavaScripted document. The watchword in event handler parameters is this which represents a reference to the current object that contains the event handler attribute. For example, consider the function and form definition in Listing 23-1. The entire user interface for this listing consists of form elements, as shown in Figure 23-1. Listing 23-1: Passing the Form Object as a Parameter Beatle Picker

Choose your favorite Beatle: John Paul George Ringo

Enter the name of your favorite Beatles song:

FORM
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Web hosting domains - 529Chapter 23 .The Form and Related Objects does

Wednesday, August 29th, 2007

529Chapter 23 .The Form and Related Objects does with this information depends on the CGI (Common Gateway Interface) programs running on the server. If your Web site runs on a server directly under your control (that is, it is in-house or hosted by a service), you have the freedom to set up all kinds of data-gathering or database search programs to interact with the user. But with some of the more consumer-oriented Internet Service Providers (ISPs), you may have no CGI support available or, at best, a limited set of popular but inflexible CGI programs available to all customers of the service. Custom databases or transactional services are rarely provided for this kind of Internet service. Regardless of your Internet server status, you can find plenty of uses for JavaScript scripts in forms. For instance, rather than using data exchanges (and Internet bandwidth) to gather raw user input and report any errors, a JavaScriptenhanced document can preprocess the information to make sure that it employs the format that your back-end database or other programs most easily process. All corrective interaction takes place in the browser, without one extra bit flowing across the Net. I devote all of Chapter 43 to these kinds of form data-validation techniques. How you define a FORM element (independent of the user interface elements described in subsequent chapters) depends a great deal on how you plan to use the information from the form s controls. If you intend to use the form completely for JavaScript purposes (that is, no queries or postings going to the server), you do not need to use the ACTION, TARGET, and METHODattributes. But if your Web page will be feeding information or queries back to a server, you need to specify at least the ACTIONand METHOD attributes. You need to also specify the TARGET attribute if the resulting data from the server is to be displayed in a window other than the calling window and the ENCTYPE attribute if your form s scripts fashion the server-bound data in a MIME type other than in a plain ASCII stream. References to form control elements For most client-side scripting, user interaction comes from the elements within a form; the FORM element object is merely a container for the various control elements. If your scripts perform any data validation checks on user entries prior to submission or other calculations, many statements have the form object as part of the reference to the element. A complex HTML document can have multiple FORM objects. Each … tag pair defines one form. You don t receive any penalties (except for potential confusion on the part of someone reading your script) if you reuse a name for an element in each of a document s forms. For example, if each of three forms has a grouping of radio buttons with the name choice, the object reference to each button ensures that JavaScript doesn t confuse them. The reference to the first button of each of those button groups is as follows: document.forms[0].choice[0] document.forms[1].choice[0] document.forms[2].choice[0] Remember, too, that you can create forms (or any HTML object for that matter) on the fly when you assemble HTML strings for writing into other windows or frames. Therefore, you can determine various attributes of a form from settings in an existing document. FORM
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

528 Part III . Document Objects Reference syntax (Web design programs)

Tuesday, August 28th, 2007

528 Part III . Document Objects Reference syntax that is compatible with the earliest scriptable browsers. Besides, the only significant additions to the defining points of the form object in newer browsers are those characteristics that all other HTML elements share. The true scriptable heart of the form object has been within the scripter s reach since NN2. FORM Object For HTML element properties, methods, and event handlers, see Chapter 15. Properties Methods Event Handlers acceptCharset handleEvent() onReset action reset() onSubmit autocomplete submit() elements encoding enctype length method name target Syntax Accessing FORM object properties or methods: (All) [window.]document.formName. property | method([parameters]) (All) [window.]document.forms[index]. property | method([parameters]) (All) [window.]document.forms[ formName ]. property | method([parameters]) (IE4+) [window.]document.all.elemID.property | method([parameters]) (IE5+/NN6) [window.]document.getElementById( elemID ).property | method([parameters]) About this object Forms and their elements are the most common two-way gateways between users and JavaScript scripts. A form control element provides the only way that users can enter textual information. Form controls also provide somewhat standardized and recognizable user interface elements for the user to make a selection from a predetermined set of choices. Sometimes those choices appear in the form of an on/off checkbox, in a set of mutually exclusive radio buttons, or as a selection from a list. As you have seen in many Web sites, the form is the avenue for the user to enter information that is sent to the server housing the Web files. Just what the server FORM
We recommend high quality webhost to host and run your jsp application: christian web host services.

The Form and (Cheapest web hosting) Related Objects Prior to the

Tuesday, August 28th, 2007

The Form and Related Objects Prior to the advent of dynamic object models and automatic page reflow, the majority of scripting in an HTML document took place in and around forms. Even with all the new DHTML powers, forms remain the primary user interface elements of HTML documents because they enable users to input information and make choices in very familiar user interface elements, such as buttons, option lists, and so on. The challenge of scripting forms and form elements often involves getting object references just right. The references can get pretty long by the time you start pointing to the property of a form element (which is part of a form, which is part of a document, which is part of a window or frame). Expanded object models of IE4+ and NN6+ include scriptable access to form-related elements that are part of the HTML 4.0 specification. One pair of elements, FIELDSET and LEGEND, provides both contextual and visual containment of form controls in a document. Another element, LABEL, provides context for text labels that usually appear adjacent to form controls. While there is generally little need to script these objects, the browsers give you access to them just as they do for virtually every HTML element supported by the browser. The Form in the Object Hierarchy Take another look at the JavaScript object hierarchy in the lowest common denominator object model (refer back to Figure 14-1). The FORM element object can contain a wide variety of form element objects (sometimes called form controls), which I cover in Chapters 24 through 26. In this chapter, however, I focus primarily on the container. The good news on the compatibility front is that much of the client-side scripting works on all scriptable browsers. While you are free to use newer ways of addressing forms and their nested elements when your audience exclusively uses the newer browsers, it can serve you well to be comfortable with the old-fashioned reference syntax. Therefore, almost all example code in this and the next three chapters uses 23 CHAPTER …. In This Chapter The FORM object as a container of form controls How to submit forms via e-mail Processing form validations LABEL, FIELDSET, and LEGEND element objects ….
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

525Chapter 22 .Image, Area, and Map Objects Properties (Web site designers)

Monday, August 27th, 2007

525Chapter 22 .Image, Area, and Map Objects Properties areas Value: Array of AREA element objects Read/Write NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5 Compatibility . . Use the areas array to iterate through all AREA element objects within a MAP element. While NN6 adheres closely to the document node structure of the W3C DOM, IE4+ provides more direct access to the AREA element objects nested inside a MAP. If you want to rewrite the AREA elements inside a MAP, you can clear out the old ones by setting the length property of the areas array to zero. Then assign AREA element objects to slots in the array to build that array. On the Example (with Listing 22-7) on the CD-ROM CD-ROM Related Items: AREA element object. … MAP.areas
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.