0

I have a window that contains several tabs, each tab has a different form but they are all labelled the same: name=form1, id=form1. I want the following jQuery function to only pick the submitted form:

//Re-enable the submit button and clear previous response messages
$(document).ready(function() {
 $("#form1").on("input change", function() {
 $('input[type="submit"]').attr('disabled', false);
$( "#responseField" ).empty();
 });
})

//Script to run when button clicked
function saveInfo(id){

var buttonId = id;

$( '#form1' ).one("submit", function( event ) {

  event.preventDefault();

  var form = document.getElementById("form1");

//the rest of the jQuery code

The challenge is that once the window is loaded, all the tabs are loaded so my script can't pick out one form from the collection of different forms with the same name and id. Anyone know a workaround for this so that the script only picks the submitted form1? I know the naming of the forms is not ideal but I'm working on someone else's code so "tuff" for me.

RayMan
  • 93
  • 1
  • 1
  • 10
  • Use classes instead of ids if the value should be repeated. – Taplar Dec 13 '17 at 20:42
  • I tried the following, it didn't work though: //Re-enable the submit button and clear previous response messages $(document).ready(function() { $(".form1").on("input change", function() { $('input[type="submit"]').attr('disabled', false); $( ".responseField" ).empty(); }); }) //Script to run when button clicked function saveInfo(id){ var buttonId = id; $( '.form1' ).one("submit", function( event ) { event.preventDefault(); var x = document.getElementsByClassName("form1"); var formData = new FormData(x[0]); – RayMan Dec 13 '17 at 23:12

0 Answers0