Form Validation for jscript. This is the requirement. I just need the code and attached to my jscode. Payment Information Validation   Validate the customer’s payment information as follows:           Expiry Date (Month) Required field Expiry Date Valid expiry date to ensure the card being used has not expired Card Number Required field, Valid Card Number   NOTE: regarding the expiry date, you MUST use the date object to ensure that your date check is dynamic.   here is the given html code.                                                             Expiry Date                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     * You must choose a month                                 * Invalid expiry date

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Form Validation for jscript.

This is the requirement. I just need the code and attached to my jscode.

Payment Information Validation

 

Validate the customer’s payment information as follows:

 

   
   

Expiry Date (Month)

Required field

Expiry Date

Valid expiry date to ensure the card being used has not expired

Card Number

Required field, Valid Card Number

 

NOTE: regarding the expiry date, you MUST use the date object to ensure that your date check is dynamic.

 

here is the given html code.

<li>                            
                                <label for="month">Expiry Date</label>
                                <select id="month" name="month">
                                    <option>- Month -</option>
                                    <option value="1">January</option>
                                    <option value="2">February</option>
                                    <option value="3">March</option>
                                    <option value="4">April</option>
                                    <option value="5">May</option>
                                    <option value="6">June</option>
                                    <option value="7">July</option>
                                    <option value="8">August</option>
                                    <option value="9">September</option>
                                    <option value="10">October</option>
                                    <option value="11">November</option>
                                    <option value="12">December</option>
                                </select>
                                <select id="year" name="year">

                                </select>
                                <p class="cardError error" id="month_error">* You must choose a month</p>
                                <p class="cardError error" id="expiry_error">* Invalid expiry date</p>
                            </li>

here is my existing jscode.

function validate(e) {
    // Hides all error elements on the page
    hideErrors();

    // Determine if the form has errors
    if (formHasErrors()) {
        // Prevents the form from submitting
        e.preventDefault();

        // When using onSubmit="validate()" in markup, returning false would prevent
        // the form from submitting
        return false;
    }

    // When using onSubmit="validate()" in markup, returning true would allow
    // the form to submit
    return true;


}


/*
 * Handles the reset event for the form.
 *
 * param e  A reference to the event object
 * return   True allows the reset to happen; False prevents
 *          the browser from resetting the form.
 */
function resetForm(e) {
    // Confirm that the user wants to reset the form.
    if (confirm('Clear order?')) {
        // Ensure all error fields are hidden
        hideErrors();

        // Set focus to the first text field on the page
        document.getElementById("qty1").focus();

        // When using onReset="resetForm()" in markup, returning true will allow
        // the form to reset
        return true;
    }

    // Prevents the form from resetting
    e.preventDefault();

    // When using onReset="resetForm()" in markup, returning false would prevent
    // the form from resetting
    return false;
}

/*
 * Does all the error checking for the form.
 *
 * return   True if an error was found; False if no errors were found
 */
function formHasErrors() {
    // Determine if any items are in the cart
    // When the cart has not items, submission of form is halted
    if (numberOfItemsInCart == 0) {
        // Display an error message contained in a modal dialog element

        const modal = document.querySelector("#cartError");
        modal.showModal();

        const closeModal = document.querySelector(".close-button");

        closeModal.addEventListener("click", () => {
            modal.close();
            document.getElementById("qty1").focus();
        });

        // Form has errors
        return true;
    }

    //    Complete the validations below

    let errorFlag = false;

    let requiredFields = ["fullname", "address", "city", "province", "postal","email", "cardname", "month", "year", "cardnumber"];

    for(let i=0; i<requiredFields.length; i++){
        let textField = document.getElementById(requiredFields[i]);
        if(!leftHasInput(textField)){
            document.getElementById(requiredFields[i] + "_error").style.display ="block";

            if(!errorFlag){
                textField.focus();
                textField.select();

            }

            //Raise the error flag
            errorFlag = true;
        }


    }

 

 

 

 

 


return errorFlag;
}

 

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
JQuery and Javascript
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education