Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JavaScript Write a simple JavaScript form that performs the following: 1- Receiv

ID: 3724264 • Letter: J

Question

JavaScript

Write a simple JavaScript form that performs the following:

1- Receives a first name and a last name in two text fields
a. The text fields are part of an html table within the form as shown in

Fig.1.
2- The form is center aligned and has the header, “Project 1”. 3- When the submit button is clicked,

The form checks whether the first name and last name fields are empty.

If any of the first name or last name fields is empty, the form returns the following message, as shown in Fig.2:

“First name and last name must be filled out!”

If both fields are filled out, the form returns the full name, consisting

of the following message, as shown in figures Fig.3 and Fig.4.

“Full Name: <Entered first name> <Space> <Entered last name>”

4- Name your file project1.html and test it in a web browser.

Explanation / Answer

project1.html

<html>

<head>

                <title>project1</title>

</head>

<body>

                <form>

                                <h2>Project 1</h2>

                <table align="center">

                                <tr>

                                                <td>First Name: </td>

                                                <td><input type="text" id="fname"/></td>

                                </tr>

                                <tr>

                                                <td>Last Name: </td>

                                                <td><input type="text" id="lname"/></td>

                                </tr>

                                <tr>

                                                <td></td>

                                                <td><input type="submit" value="sumbit"/></td>

                                </tr>

                </table>

                </form>

                <script>

                                function display()

                                {

                                                var fname = document.getElementById("fname").value; //get first name

                                                var lname = document.getElementById("lname").value; //get second name

                                                //validate and print message

                                                if(fname === "" || lname === "")

                                                                document.write("First name and last name must be filled out!");

                                                else

                                                                document.write("Full Name: " + fname + " " + lname);

                                }

                </script>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote