Web hosting compare - 107Chapter 9Forms and Form ElementsFor other functions, you
107Chapter 9Forms and Form ElementsFor other functions, you may wish to receive a reference to the entire form, rather than justthe object calling the function. This is certainly true if the function needs to access other ele- ments of the same form. Because every form control object contains a property that points tothe containing form, you can use the thiskeyword to reference the current control, plus itsformproperty as this.form, as in The function definition should then have a parameter variable ready to be assigned to theform object reference. Again, you decide the name of the variable. I tend to use the variablename 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 theperformance of two separate acts. This page makes believe it is connected to a database ofBeatles songs. When you click the Process Data button, it passes the formobject, which theprocessData()function uses to access the group of radio buttons inside a forloop. Additional references using the passed formobject extract the valueproperties of theselected 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 valueproperty of the song fieldinside the function. Listing 9-5:Passing a Form Object and Form Element to Functions
Continued