Books
in black and white
Main menu
Home About us Share a book
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 .. 74 75 76 77 78 79 < 80 > 81 82 83 84 85 86 .. 118 >> Next

}
// Otherwise, we still have to check the rest of
// the digits, so step through the inputValue one
// character at a time and set result = false
// if any non-numeric digits are encountered.
else {
for (var i=0; i<inputValue.length; i++) { if (inputValue.charAt(i) I = ” ”) {
if (IparseFloat(inputValue.charAt(i))) { result = false break
}
}
}
}
// Return true (inputValue is a valid number) or // false (it's invalid).
return result
}
////////////////////////////////////////////////////// // Checks to see whether an input value contains ”@”
// and ”.”
////////////////////////////////////////////////////// function isAValidEmail(inputValue) {
var foundAt = false var foundDot = false
// Step through the inputValue looking for // ”@” and ”.”
for (var i=0; i<=inputValue.length; i++) { if (inputValue.charAt(i) == ”@” ) { foundAt = true
}
else if (inputValue.charAt(i) == ”.”) { foundDot = true
}
Chapter 12: Handling Forms 233
}
// If both ”@” and ”.” were found, assume // the e-mail address is valid; otherwise,
// return false so the calling code knows // the e-mail address is invalid.
if (foundAt && foundDot) { return true
}
else {
return false
}
}
////////////////////////////////////////////////////// // Checks to see if an input value contains ten or more // numbers. This approach lets users type in U.S.-// style phone formats, such as (123)456-7890, as // well as European-style (such as 123.456.7890). ////////////////////////////////////////////////////// function isAValidPhoneNumber(inputValue) { var digitsFound = 0
// Step through the inputValue to see how // many digits it contains.
for (var i=0; i<=inputValue.length; i++) { if (isANumber(inputValue.charAt(i))) { digitsFound++
}
}
// If inputValue contains at least 10 // digits, assume it is a valid phone number. if (digitsFound >= 10) { return true
}
else {
return false
}
}
////////////////////////////////////////////////////// // Check for the existence of characters.
// (Spaces aren't counted.) //////////////////////////////////////////////////////
(continued)
234 Part IV: Interacting with Users______________
Listing 12-7 (continued)
function exists(inputValue) { var aCharExists = false
// Step through the inputValue, using the charAt()
// method to detect non-space characters.
for (var i=0; i<=inputValue.length; i++) { if (inputValue.charAt(i) != ” ” && inputValue.charAt(i) != "”) { aCharExists = true break
}
}
return aCharExists
}
//////////////////////////////////////////////////////
// Perform cross-field checks that can't be performed // until all of the data has been entered. //////////////////////////////////////////////////////
// validateForm() performs all dependent field validation
function validateForm() {
var rc = true
// Dependent check #1: ensuring a service category is selected
///////////////////////////////////////////////////
// Visitors need to check one of the following // choices in order to receive an accurate quote:
// whether they're interested
// in design, maintenance, or promotion services.
///////////////////////////////////////////////////
if (!document.quoteForm.designChoice.checked && !document.quoteForm.maintChoice.checked && !document.quoteForm.promoChoice.checked) {
alert(”Please check whether you're interested in our design, maintenance, or promotion services so we can give you a more accurate quote. Thanks!”) rc = false
}
// Dependent check #2: ensuring that a company name exists if a // user checked "employee”
Chapter 12: Handling Forms 235
///////////////////////////////////////////////////
// If visitors are employees, they need to specify // the name of their company. ///////////////////////////////////////////////////
if (document.quoteForm.bizChoice[1].checked) { if (Idocument.quoteForm.corpName.value) {
alert("You've specified that you're an employee, so could you please type in the name of the company you work for? Thanks!”) rc = false
}
}
// Dependent check #3: double-checking that both first and // last names exist
///////////////////////////////////////////////////
// Visitors need to include their first and last // names.
///////////////////////////////////////////////////
if (Idocument.quoteForm.firstName.value || Idocument.quoteForm.lastName.value) {
alert("Please type in your entire name (both first and last). Thanks!”) rc = false
}
// Dependent check #4: ensuring that users enter either an e-mail // address or a phone number
///////////////////////////////////////////////////
// Visitors need to specify either an e-mail // address or a telephone number. /////////////////////////////////////////////////// if (Idocument.quoteForm.emailChoice.checked && Idocument.quoteForm.phoneChoice.checked) {
alert("Please let us know whether you'd like us to contact you by e-mail or by phone. ThanksI”) rc = false
}
// Dependent check #5: ensuring that an e-mail address exists // (if a user chose the e-mail contact option)
Previous << 1 .. 74 75 76 77 78 79 < 80 > 81 82 83 84 85 86 .. 118 >> Next