Q:

Is it possible to call on form in a page where there are two with Ajax?

I have two forms on one page, one form to upload files and another one that comes on a popup asking for the email when the file has been uploaded. Both use ajax and I'm having some trouble handling both of them.
I'd like each of my ajax code to only work on their own respective form instead of the first form found on my html page (right now only the higest <form></form> is exectued by my ajax codes).
AJAX : 
# for uploading files form
  $("#fileupload").fileupload({
    dataType: 'json',
    sequentialUploads: true, 
    start: function (e) {  
      $("#modal-progress").modal("show");
    },
    ...
    done: function (e, data) {
      if (data.result.is_valid) {
        ...
      }
    }
  });

# for email form
$(document).on('submit', '#formTwo', function(e){
    e.preventDefault();

    $.ajax({
        # is there a command to specify in which form it should run ?
        type:'POST',
        url:'/tools/newsletter/',
        data:{
            email:$('#email').val(),
            csrfmiddlewaretoken:$('#formTwo input[name=csrfmiddlewaretoken]').val(),
        },
    });

    $("#modal-progress").modal("hide");
});

forms.html
<!-- Email form -->
<form id="formTwo" method="post" action="newsletter">
  ...
  <input id="email" maxlength="255" placeholder="Votre adresse email" name="email" type="text" class="form-control">
  <input type="submit" class="btn btn-success">
</form>

<!-- Uploading files form -->
<form id="formOne" method="post" enctype="multipart/form-data" action="{% url 'basic_upload' %}">
...
<input id="fileupload" type="file" name="file" multiple>
</form>

How can I resolve this ?

A:

You can use $(this).is(selector) in an if statement to verify what form are you dealing, like
$(document).on('submit', '#formTwo, #formOne', function(e){
    e.preventDefault();

    if($(this).is('#formTwo')) {
        $.ajax({
            type:'POST',
            url:'/tools/newsletter/',
            data: {
                email:$('#email').val(),
                csrfmiddlewaretoken:$('#formTwo input[name=csrfmiddlewaretoken]').val(),
            },
        });
    } else if ($(this).is('#formOne')) {
        // formOne code 
    }

    $("#modal-progress").modal("hide");
});

