1

I have some JS variables set in the head due to them outputting ACF values from WordPress posts (in this case URLs).

<head>
<script>
 pdf1 = 'https://url.com/file1.pdf';
 pdf2 = 'https://url.com/file2.pdf';
 ...
</script>
</head>

I need to output these values on the submission of a single form, and redirect to the URLs in the vars above. The values should increment based on the number in the vars. I also need to increment the cookie ID too.

Where X exists, I need something to increment the values.

$('#form_id1').submit(function(i, varX) {
    $(this).each(function() {
        // some code to close a modal I already have.

        setTimeout(function() {
            jQuery.cookie('cookie-' + i);

            // redirect to the selected URL
            jQuery(location).attr('href', pdfX);
        }, 1000);
    })

});

I've done some research and I've tried using pdf++.

I've tried something like: jQuery(location).attr('href', pdf + 1);

Below is the closest I got.

id = 1;
$('#form_id1').submit(function(i, pdfX) {
    $(this).each(function() {
        id = id + 1;
        // some code to close a modal I already have.

        setTimeout(function() {
            jQuery.cookie('cookie-' + id);

            // redirect to the selected URL
            jQuery(location).attr('href', pdfX);
        }, 1000);
    })

});
Peter
  • 29,454
  • 5
  • 48
  • 60
bensilverfox
  • 67
  • 1
  • 5
  • 1
    Side note; `$(this).each` is unnecessary. `$('#form_id')` will only ever find one element. – Taplar Oct 08 '19 at 15:10
  • https://stackoverflow.com/questions/1920867/get-global-variable-dynamically-by-name-string-in-javascript – Lapskaus Oct 08 '19 at 15:28

0 Answers0