Dana
Dana

Reputation: 19

2 Ajax forms in a page but only one is working

I have two forms in a page. But only one works.

This is the website link - http://baysquare-dubai.com/businessbay/real-estate.html

I have two scripts for each form.

Script 1:

 <script>
 $(document).ready(function() {
    $("#submit-form-button").click(function() { submitForm(); });
});
function submitForm() {

        $.ajax({
      type: "POST",
      url: "http://famproperties.com/real_estate/property/contact/lead/",
      data: {  
      NAME:   $("#NAME").val(), 
      EMAIL:  $("#EMAIL").val(), 
      MOBILE: $("#MOBILE").val(), 
      NOTE:   $("#NOTE").val(),
      SOURCE: 'BAY.SQUARE',
      CITY: 'ADD CITY',
      },

      success: function() {

         alert ("we will contact you soon ..");

      },
      dataType: 'html'
   });
$("#NAME").val(''); 
 $("#EMAIL").val(''); 
 $("#MOBILE").val(''); 
 $("#NOTE").val('');

};
</script>

In the 2nd script, it is the same but with different IDs.

Need help!

Upvotes: 0

Views: 96

Answers (1)

Jasper Seinhorst
Jasper Seinhorst

Reputation: 1074

You can't make two different functions with the same name. For your second form add the function "submitForm2" instead of "submitForm". Call the right functions like this:

$(document).ready(function() {
    $("#submit-form-button").click(function() { submitForm(); });
});

$(document).ready(function() {
    $("#submit-form-button_v2").click(function() { submitForm2(); });
});

Upvotes: 1

Related Questions