532 Part III . Document Objects Reference The (Web hosting providers)
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.