Question: Develop an HTML form that could be used to enter book information (Books, Authors, and Publishers) into our fictional book database system. , feel free
Develop an HTML form that could be used to enter book information (Books, Authors, and Publishers) into our fictional book database system. , feel free to start with the
HTML/JavaScript template include the following Add JavaScript processing to make sure that the information is correctly verified Have your form use more then just character text fields ... radiobuttons, pick lists, and other elements make your form easier to use and you don't need to do lots of JavaScript checks.
What fields would be mandatory ... which could be left blank? How would a user know what fields are mandatory?
Template
//
// Template: License Form Validator
//
// Initialize any global variables to use in processing form data
//-----------------------------------------------------------------------------
//
// Name: validateLicense
//
// Description - This is the main entry point that is initially called
// when the user hits the "calculate" button in the
// HTML form. It will make various calls to functions and
// built-in functions to verify the fields that need to
// be validated (checked for any errors).
//
// Alert buttons are used to indicate issues with the
// form field values, and a final alert is used to indicate
// that the license form is validated and correct. The
// final alert will only display if no validation issues are
// found.
//
// In the real world you could then be confident to do
// something with your form data, such as write information
// to a file or send it to a program (e.g., Perl, Java, Ruby)
// on a web server that would connect to a database and insert
// the valid field information.
//
// Parameters: None
//
// Returns: 0 - successfully passed all validation
//
//----------------------------------------------------------------------------
function validateLicense() {
//
// Check all mandatory form fields to make sure they are not empty.
// If the field is empty then return (exit) from the function to put up an alert
//
// 1) Create variables to capture the values for all form field you are using
var licenseNumber = document.myLicense.licenseNumber.value;
// add other variables as needed for fields you want to check
// 2) Check that all mandatory fields have values
// If the License Number field is empty then exit the function.
if (fieldEmpty ("License Number", licenseNumber) ) { return; }
// Add other mandatory fields checks here using the fieldEmpty function
// 3) As needed, start validating fields if they have values that need to be verified
// Is License Number Alphanumeric (only contains letters and numbers)?
// NOTE: use the fieldAlphanumberic function and alert if needed
if ( fieldAlphanumeric ( "License Number", licenseNumber ) ) { return; }
// Validate values in other fields as needed ... use built in functions like isNaN and
// others as needed
// 4) S U C C E S S
//
// if everything works and it gets this far, all validations have passed, just present an alert message
alert ("License Information is Valid");
return 0; /* success */
}
//-----------------------------------------------------------------------------
//
// Name: fieldAlphanumeric
//
// Description - Checks to see if a field value is only AlphaNumeric, only
// letters (A-Z and a-z) and digits (0-9) are allowed).
//
// Sample Valid Values - 12A, abc12, and 9a1b12c
//
// Sample Invalid Value - 83$A% (has a $ and % character)
//
// Parameters: fieldName - The Field Name Label on the HTML form
// fieldValue - The actual value within the field being tested
//
// Returns: 1 - fieldValue contains non alphanumeric characters
// 0 - fieldValue contains alphanumeric characters
//
//----------------------------------------------------------------------------
function fieldAlphanumeric (fieldName, fieldValue)
{
var msg =" must contain only letters and numbers";
// these is a regular expression test (we'll cover this soon)
if ( /[^A-Za-z0-9]/.test(fieldValue) ) {
alert (fieldName + (msg));
return 1; // fails, contains non alphanumeric characters
}
else {
return 0; // passes, contains only alphanumeric characters
}
}
//-----------------------------------------------------------------------------
//
// Name: fieldEmpty
//
// Description - Determines if a given fieldValue is empty
//
// Parameters: fieldName - The Field Name Label on the HTML form
// fieldValue - The actual value within the field being tested
//
// Returns: 1 - fieldValue is empty
// 0 - fieldValue
//
//----------------------------------------------------------------------------
function fieldEmpty (fieldName, fieldValue) {
var msg=" is a required field";
if(fieldValue == "") {
alert (fieldName +(msg));
return 1;
}
else {
return 0;
}
}
// add other functions if you wish, but not mandatory or expected
myLicense Form Validator
Step by Step Solution
There are 3 Steps involved in it
It seems like you have a partial question and an HTMLJavaScript template The missing part of the problem is related to how the HTML form should handle ... View full answer
Get step-by-step solutions from verified subject matter experts
