Solution: Build a Simple Form App
Handles a form submission to display a personalized greeting with the user’s name and age.
Explanation:
The
submitevent is captured on the form with ID"userForm", ande.preventDefault()stops the page from reloading.It reads the name and age values from their respective input fields.
If the name is left blank, it shows a message asking the user to enter their name.
Otherwise, it displays a message like “Hello, Alex! You are 25 years old.” inside the element with ID
"output".
Solution: Build a Simple Form App
Handles a form submission to display a personalized greeting with the user’s name and age.
Explanation:
The
submitevent is captured on the form with ID"userForm", ande.preventDefault()stops the page from reloading.It reads the name and age values from their respective input fields.
If the name is left blank, it shows a message asking the user to enter their name.
Otherwise, it displays a message like “Hello, Alex! You are 25 years old.” inside the element with ID
"output".