108Part IIJavaScript TutorialListing 9-5(continued) Choose your favorite Beatle: (Best web hosting site)

108Part IIJavaScript TutorialListing 9-5(continued)

Choose your favorite Beatle: JohnPaulGeorgeRingo

Enter the name of your favorite Beatles song:

Get to know the usage of the thiskeyword in passing formand form elementobjects tofunctions. The technique not only saves you typing in your code, but it also ensures accuracyin references to those objects. Submitting and Prevalidating FormsThe scripted equivalent of submitting a form is the formobject s submit()method. All youneed in the statement is a reference to the form and this method: document.forms[0].submit(); Before you get ideas about having a script silently submit a form to a URL bearing themailto:protocol, forget it. Because such a scheme could expose visitors e-mail addresseswithout their knowledge, mailto:submissions are either blocked or revealed to users as asecurity precaution. Before a form is submitted, you may wish to perform some last-second validation of data inthe form or in other scripting (for example, changing the form s actionproperty based onuser choices). You can do this in a function invoked by the form s onsubmitevent handler. Specific validation routines are beyond the scope of this tutorial (but are explained in sub- stantial detail in Chapter 43 on the CD-ROM), but I want to show you how the onsubmiteventhandler works. You can let the results of a validation function cancel a submission if the validation showssome incorrect data or empty fields. To control submission, the onsubmitevent handlermust evaluate to returntrue(to allow submission to continue) or returnfalse(to cancelsubmission). This is a bit tricky at first because it involves more than just having the functioncalled by the event handler return trueor false. The returnkeyword must be part of thefinal evaluation.
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services