I am trying to loop the jQuery code below. Each form has a unique id
starting from #product_1
to #product_35
. I don't want to copy+paste the code below:
$('#product_1').on('submit', function(e) {
e.preventDefault();
var jqxhr = $.ajax({
url: "https://script.google.com/macros/s/SAMPLE/exec",
method: "GET",
dataType: "json",
data: $('#product_1').serialize()
}).success();
})};
I came up with the code below and I'm kinda stuck to loop the code.
var i;
for (i = 1; i < 36; i++) {
$('#product_' + 'i').on('submit', function(e) {
e.preventDefault();
var jqxhr = $.ajax({
url: "https://script.google.com/macros/s/SAMPLE/exec",
method: "GET",
dataType: "json",
data: $('#product_' + 'i').serialize()
}).success();
})
};
Could anyone help me to fix this? Many thanks in advance