0

Hi I want to download when input type submit is clicked. Here is my code

<input type="submit" value="Try a sample" class="wpcf7-form-control wpcf7-submit">

<a href="<?php echo get_template_directory_uri()?>/pdf/AttackonNantucket.pdf" class="ddownload-button" download>Ram</a>
RonyLoud
  • 2,408
  • 2
  • 20
  • 25
Mr.Pandya
  • 1,899
  • 1
  • 13
  • 24
  • 1
    Possible [duplicate of 11620698](http://stackoverflow.com/questions/11620698/how-to-trigger-a-file-download-when-clicking-an-html-button-or-javascript) –  Feb 07 '17 at 10:47
  • 1
    Possible duplicate of [How to trigger a file download when clicking an html button or javascript](http://stackoverflow.com/questions/11620698/how-to-trigger-a-file-download-when-clicking-an-html-button-or-javascript) –  Feb 07 '17 at 10:48

1 Answers1

1

You need to do this.

$('input[type="submit"]').on('click', function(){
  $(this).next().get(0).click();
})

Clicking on the submit , trigger an click for the next element which is hyper link in this case.

As you have a class on the href you could do this too.

$('input[type="submit"]').on('click', function(){
  $('.ddownload-button').get(0).click();
})

$('input[type="submit"]').on('click', function() {
  $(this).next().get(0).click();
})

$('a').on('click', function() {
  alert('Ram clicked')
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="submit" value="Try a sample" class="wpcf7-form-control wpcf7-submit">
<a href="<?php echo get_template_directory_uri()?>/pdf/AttackonNantucket.pdf" class="ddownload-button" download>Ram</a>
Parvez Rahaman
  • 4,269
  • 3
  • 22
  • 39