/*
 * Mailchimp AJAX form submit VanillaJS
 * Vanilla JS
 * Author: Michiel Vandewalle
 * Github author: https://github.com/michiel-vandewalle
 * Github project: https://github.com/michiel-vandewalle/Mailchimp-AJAX-form-submit-vanillaJS
 */

(function () {
    document.getElementsByTagName('form')[0].addEventListener('submit', function (e) {
        e.preventDefault();

        // Check for spam
        if(document.getElementById('js-validate-robot').value !== '') { return false }

        // Get url for mailchimp
        var url = this.action.replace('/post?', '/post-json?');

        // Add form data to object
        var data = '';
        var inputs = this.querySelectorAll('#js-form-inputs input');
        for (var i = 0; i < inputs.length; i++) {
            data += '&' + inputs[i].name + '=' + encodeURIComponent(inputs[i].value);
        }

        // Create & add post script to the DOM
        var script = document.createElement('script');
        script.src = url + data;
        document.body.appendChild(script);

        // Callback function
        var callback = 'callback';
        window[callback] = function(data) {

            // Remove post script from the DOM
            delete window[callback];
            document.body.removeChild(script);

            // Display response message
            document.getElementById('js-subscribe-response').innerHTML = data.msg
        };
    });
})();
@@ -246,24 +246,88 @@
 nction () %7B%0A
+    if (document.getElementsByTagName('form').length %3E 0) %7B%0A    
     document
@@ -409,16 +409,20 @@
         
+ 
+   
 e.preven
@@ -438,24 +438,28 @@
 );%0A%0A        
+    
 // Check for
@@ -464,16 +464,20 @@
 or spam%0A
+    
         
@@ -564,16 +564,20 @@
         
+    
 // Get u
@@ -593,16 +593,20 @@
 ilchimp%0A
+    
         
@@ -670,16 +670,20 @@
         
+  
+  
 // Add f
@@ -705,24 +705,28 @@
 ect%0A        
+    
 var data = '
@@ -728,16 +728,20 @@
 a = '';%0A
+    
         
@@ -809,16 +809,20 @@
         
+ 
+   
 for (var
@@ -851,24 +851,28 @@
 gth; i++) %7B%0A
+    
             
@@ -945,16 +945,20 @@
 value);%0A
+    
         
@@ -964,24 +964,28 @@
  %7D%0A%0A        
+    
 // Create & 
@@ -1003,32 +1003,36 @@
 ript to the DOM%0A
+    
         var scri
@@ -1078,16 +1078,20 @@
         
+   
+ 
 script.s
@@ -1107,16 +1107,20 @@
 + data;%0A
+    
         
@@ -1159,24 +1159,28 @@
 );%0A%0A        
+    
 // Callback 
@@ -1192,24 +1192,28 @@
 ion%0A        
+ 
+   
 var callback
@@ -1227,16 +1227,20 @@
 lback';%0A
+    
         
@@ -1276,16 +1276,20 @@
 ata) %7B%0A%0A
+    
         
@@ -1339,16 +1339,20 @@
         
+    
 delete w
@@ -1368,16 +1368,20 @@
 lback%5D;%0A
+    
         
@@ -1432,16 +1432,20 @@
         
+  
+  
 // Displ
@@ -1464,16 +1464,20 @@
 message%0A
+    
         
@@ -1562,19 +1562,27 @@
     
-%7D;%0A
+    %7D;%0A    
     %7D);%0A
 %7D)()
@@ -1581,9 +1581,16 @@
 %7D);%0A
+    %7D%0A
 %7D)();
+%0A

Make sure the subscribe form is available before running the script