Search code examples
htmlrequired

Require attribute in html5


In html5 there is a required attribute and i have used it in my code but even if i leave the field empty its not saying "This field is required". Please can anyone answer why im not getting the pop up box saying the message. The following is my code:

<form id="contact" method="post">
<label for="firstName">First Name:</label><br>
<input type="text" name="firstName" placeholder="First Name" required><br>
<label for="lastName">Last Name:</label><br>
<input type="text" name="lastName" placeholder="Last Name"><br>
<label for="email">Email:</label><br>
<input type="email" name="email" placeholder="Email"><br>
<label for="password">Password:</label><br>
<input type="password" name="password" placeholder="Password"><br>
<input type="button" name="submit" value="Submit">
</form>


Solution

  • Change the button to submit

    <form id="contact" method="post">
    <label for="firstName">First Name:</label><br>
    <input type="text" name="firstName" placeholder="First Name" required><br>
    <label for="lastName">Last Name:</label><br>
    <input type="text" name="lastName" placeholder="Last Name"><br>
    <label for="email">Email:</label><br>
    <input type="email" name="email" placeholder="Email"><br>
    <label for="password">Password:</label><br>
    <input type="password" name="password" placeholder="Password"><br>
    <input type="submit" name="submit" value="Submit">
    </form>