howto to put multiple form using same function??

howto to put multiple form using same function??

hi,

got a problem with this form that will be displayed on the same page for each product/item.
However it does not work only if i use it only once.
What do i need to change in order to make it work for each form.
I do realize that is has to be unique. But what should be done in the Function:

  1. $(function() {
      $('.error').hide();
      $(".button").click(function() {
        $('.error').hide();
           
          var name = $("input#name").val();
            if (name == "") {
          $("label#name_error").show();
          $("input#name").focus();
          return false;
        }

           
            var dataString = 'name='+ name;
           
            $.ajax({
          type: "POST",
          url: "/mailer.php",
          data: dataString,
          success: function() {
            $('#contact_form').html("<div id='message'></div>");
            $('#message').html("<h2>Contact Form Submitted!</h2>")
            .append("<p>We will be in touch soon.</p>")
            .hide()
            .fadeIn(1500, function() {
              $('#message').append("<img id='checkmark' src='images/check.png' />");
            });
          }
         });
        return false;
        });
    });






























sample form 1
  1. <div id="contact_form1">
    <form name="contact" method="post" action="">
    <label for="name" id="name_label">Name</label>
    <input type="text" name="name" id="name" size="30" class="text-input" />
    <label class="error" for="name" id="name_error">missing!</label>
    <input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
    </form>
    </div>






sample form 2

  1. <div id="contact_form2">
    <form name="contact" method="post" action="">
    <label for="name" id="name_label">Name</label>
    <input type="text" name="name" id="name" size="30" class="text-input" />
    <label class="error" for="name" id="name_error">missing!</label>
    <input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
    </form>
    </div>