使按钮填写联系表单的一部分

时间:2017-05-18 17:48:55

标签: javascript html

我在我提供的SEO服务下面放了一个按钮,当他们点击它时,我希望它将它们指向下面的联系表格并填写所需的服务"区域为" SEO"。这可能吗?



<!-- MY FORM THAT I WANT FILLED OUT AFTER THEY CLICK A BUTTON -->

<form id="contact-form" class="form" action="contact.php" method="POST" role="form">
              <div class="form-group">
                  <label class="form-label" for="name"></label>
                  <input type="text" class="form-control" id="name" name="name" placeholder="Your Name" tabindex="1" required>
              </div>                            
              <div class="form-group">
                  <label class="form-label" for="email"></label>
                  <input type="email" class="form-control" id="email" name="email" data-constraints="@NotEmpty @Email" placeholder="Your Email" tabindex="2" required>
              </div>                            
              <div class="form-group">
                  <label class="form-label" for="subject"></label>
                  <input type="text" class="form-control" id="subject" name="subject" placeholder="Service Needed" tabindex="3">
              </div>                            
              <div class="form-group">
                  <label class="form-label" for="comments"></label>
                  <textarea rows="5" cols="50" name="comments" class="form-control" id="comments" placeholder="Message..." tabindex="4" required></textarea>                                 
              </div>
              <div class="text-center">
                  <button type="submit" value="send" class="btn btn-start-order">Send Message</button>
              </div>
          </form>



<!-- BUTTON I USE -->
<a href="index.html#contact" class="btn btn-default">get a quote</a>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

$.ready(function(){
    $('#myButtonID').click(function(){
         $('#subject').val('SEO');
         event.preventDefault(); // prevent default anchor tag action otherwise animation wont work
         $('html, body').animate({scrollTop: $('#contact-form').offset().top}, 300 /*duration*/);
         return false;
    });

});