Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Form validation not working

I'm running into an error with form validation. When I configure the html to trigger the 'required' validation on a <button> then the form validation works but the button does not take the user to the next page

When I replace the <button> with a <a> then the page successfully goes to the next page but the form validation does not work

I've attempted to configure the <button> to link to the next page but can't seem to get it to work. Please assist

HTML:

    <form class="form-horizontal" id="validateForm" method="post">
            <div class="form-group text-left">
              <label for="price">Price*</label>
              <input type="text" class="form-control" id="price" placeholder="Your offer price" required>
            </div>
  <button type="submit" class="btn btn-primary">Next page</button>
          </form>

1 Answer

Your button should send your form data to your backend through a post request. Your backend can then redirect the user to the next page.