Form Validation

Create a simple HTML form with two input fields: one for the username and one for the password. Add a submit button to the form. The form should have the following behaviour:


  • - When the user clicks the submit button, if the username or password field is empty, an error message should be displayed below the respective field.

  • - If both fields are filled, the form should display a message saying 'Form submitted successfully' below the submit button.

  • - Use JavaScript to handle the form validation and display the messages.
Expected Output:
</>
Code
Loading...
Output