Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Javascript for dummies 4th edition - Veer E.V

Veer E.V Javascript for dummies 4th edition - Wiley publishing , 2004. - 387 p.
ISBN: 0-7645-7659-3
Download (direct link): javascriptfordummies2005.pdf
Previous << 1 .. 75 76 77 78 79 80 < 81 > 82 83 84 85 86 87 .. 118 >> Next

///////////////////////////////////////////////////
// If visitors tell us they want us to contact them // by e-mail, alert them if they haven't put in // their e-mail address (same with telephone). ///////////////////////////////////////////////////
(continued)
236 Part IV: Interacting with Users______________
Listing 12-7 (continued)
if (document.quoteForm.emailChoice.checked &&
lisAValidEmail(document.quoteForm.emailAddr.value)) {
alert("We can't contact you via e-mail unless you give us a valid e-mail address. Thanks!”) rc = false
}
else {
if (document.quoteForm.phoneChoice.checked && !isAValidPhoneNumber(document.quoteForm.phoneNumber.value)) {
alert("We can't contact you via phone unless you give us your phone number (make sure to include your area code). Thanks!”) rc = false }
}
if (rc) {
// If the rc variable is non-zero, then the form data // passed with flying colors!
alert("Thanks! We'll contact you with a quote shortly.”)
}
return rc
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<H1>Order form example</H1>
<HR>
<P>
<HR>
<TABLE WIDTH=”100%” CELLSPACING=”10” CELLPADDING=”10” BORDER=0>
<TR>
<TD>
<FONT FACE=”Helvetica, Arial, Verdana" SIZE=”2”>
//Dependent validation checks execute when the user attempts to submit the form <FORM NAME="quoteForm" onSubmit="return validateForm();">
<P>
<B>Which of our services are you interested in?</B> (Check all that apply.)
<P>
Website design <INPUT TYPE="CHECKBOX" NAME="designChoice" VALUE="design"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Website maintenance <INPUT TYPE="CHECKBOX" NAME="maintChoice" VALUE="maint">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Online promotion
<INPUT TYPE="CHECKBOX" NAME="promoChoice" VALUE="promo">
<P>
Chapter 12: Handling Forms 237
<B>Why do you want a Website? (Or, if you already have one, what do you use it for?)</B>
<P>
<TEXTAREA NAME="purpose" COLS=”60” ROWS=”5” WRAP="VIRTUAL">
</TEXTAREA>
<P>
<B>Do you want to incorporate photos into your site?</B>
<BR>
yes (INPUT TYPE="RADIO" NAME="pixChoice" VALUE="hasPix" CHECKED:.........
no <INPUT TYPE="RADIO" NAME="pixChoice" VALUE="hasNoPix">
<P>
<B>Do you have one or more products you'd like to promote/sell on your site?</B> <BR>
yes <INPUT TYPE="RADIO" NAME="cdChoice" VALUE="hasProducts" CHECKED:..........
no <INPUT TYPE="RADIO" NAME="cdChoice" VALUE="hasNoProducts">
<P>
<B>Are you a small business owner, or do you work for a large corporation?</B> <BR>
small business owner <INPUT TYPE="RADIO" NAME="bizChoice" VALUE="isOwner" CHECKED>
employee <INPUT TYPE="RADIO" NAME="bizChoice" VALUE="isEmployee">
<P>
<B>If you work for a corporation, what's the name?</B>
<INPUT TYPE="TEXT" NAME="corpName" SIZE="25">
<P>
<B>Is there anything else you think we need to know in order to give you an accurate price quote?</B>
<P>
<TEXTAREA NAME="extraInfo" COLS="60" ROWS="5" WRAP="VIRTUAL">
</TEXTAREA>
<P>
<TABLE>
<TR>
<TD>
<FONT FACE="Helvetica, Arial, Verdana" SIZE="2">
<B>Your first name:</B>
</TD>
<TD>
<FONT FACE="Helvetica, Arial, Verdana" SIZE="2">
<B>Last name:</B>
</TD>
</TR>
<TR>
<TD>
<INPUT TYPE="TEXT" NAME="firstName" SIZE="25" onBlur="if (!exists(this.value)) { alert('Please enter a first name'); }">
</TD>
<TD>
<INPUT TYPE="TEXT" NAME="lastName" SIZE="35" onBlur="if (!exists(this.value)) { alert('Please enter a last name') }">
</TD>
(continued)
238 Part IV: Interacting with Users______________
Listing 12-7 (continued)
</TR>
<TR>
</TR>
<TR>
<TD COLSPAN="2">
<FONT FACE="Helvetica, Arial, Verdana" SIZE="2">
<B>How would you like us to contact you (e-mail, phone, or both)?</B>
</FONT>
</TD>
</TR>
<TR>
<TD ALIGN="RIGHT">
<FONT FACE="Helvetica, Arial, Verdana" SIZE="2"> e-mail<INPUT TYPE="CHECKBOX" NAME="emailChoice" VALUE="email">
</FONT>
</TD>
<TD>
(INPUT TYPE="TEXT" NAME="emailAddr" SIZE="35">
</TD>
</TR>
<TR>
<TD ALIGN="RIGHT">
<FONT FACE="Helvetica, Arial, Verdana" SIZE="2">
telephone <INPUT TYPE="CHECKBOX" NAME="phoneChoice" VALUE="phone">
</TD>
<TD>
(INPUT TYPE="TEXT" NAME="phoneNumber" SIZE="15">
</TD>
</TR>
</TABLE>
<P>
<CENTER>
<INPUT TYPE="SUBMIT" VALUE="Submit your quote request"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT TYPE="RESET" VALUE="Clear the form">
</HTML>
In the code in Listing 12-7, the validateForm() function, which performs five dependent field validation routines, executes when the user attempts to submit the form. (Attaching the vaidateForm() function to the quoteForm form’s onSubmit event handler sees to that!)
Chapter 13
Handling User-Initiated Events
In This Chapter
^ Getting acquainted with the difference between events and event handlers ^ Taking a look at the events associated with different objects ^ Seeing event handlers in action
7
# avaScript helps you transform static Web pages into interactive Web-based applications. And what’s the feature that makes this client-side interactivity possible? The humble and lovable event handler. You can think of event handlers as little software bungee cords that bind custom JavaScript code to events, such as clicking a button or a link, loading a page, typing data into an input field, and so on.
Previous << 1 .. 75 76 77 78 79 80 < 81 > 82 83 84 85 86 87 .. 118 >> Next