charly
charly

Reputation: 193

required attribute is not working in html form

I can't figure out why the required attribute seems to not be working even thought its inside the form tag, and I know my simple code seems to be okay. Is there anything I am missing or I should do to make this work?

<form>
  <div class="form-group ">

    <label for="name"> Name :</label>
    <input type="text" class="form-control" id="name" required />
  </div>
  <div class="form-group">
    <label for="comment">Email :</label>
    <input type="text" class="form-control" id="comment" required /> </div>
  <div class="form-group">
    <input type="button" id="submit" class="btn btn-xl" style="background:#169CF7;" value="Submit">
  </div>
</form>

Upvotes: 0

Views: 46

Answers (2)

Christoph Dethloff
Christoph Dethloff

Reputation: 86

type="button" should be type="submit" instead. Then it will work.

Upvotes: 2

Quentin
Quentin

Reputation: 943143

The test for required only runs when the form is submitted.

Your form doesn't have a submit button, so you can't submit it.

Add a submit button (or convert your type="button" to a submit button).

Upvotes: 2

Related Questions