Prevent Default for Multiple Form

by syamsoul

HTML

<div class="add-comment">
  <form id="comment-form">
    <textarea id="comment-content" name="comment" placeholder="Leave a comment"></textarea>
    <br>
    <button type="submit">Submit</button>
  </form>
</div>

<div class="poll">
  <h1 class="title">Poll</h1>
  <h3>Poll Question</h3>
    <form id="poll-form">
      <input type="radio" name="vote" value="0">
      Choice 1
      <br>
      <input type="radio" name="vote" value="1">
      Choice 2
      <br>
      <input type="radio" name="vote" value="2"> 
      Choice 3
      <br>
      <input type="radio" name="vote" value="3">
      Choice 4
      <br>
      <button type="submit">Submit</button>
    </form>
</div>

JavaScript

$("#comment-form").submit(function(event){
    event.preventDefault();
    alert('comment ajax');
});

//ajax stuff for adding the comment, addComment() etc.

$("#poll-form").submit(function(event){
    event.preventDefault();
    alert('poll ajax');
});