Solved

Javascript click attachment control to download

  • 21 March 2019
  • 2 replies
  • 73 views

Has anyone ever tried to click an attachment control in the background?
I'm finding it very difficult. Normally, if it was just a button, a simple jquery that looks like this would do the trick: 

$('[name="ButtonName"]').click();

however, apparently the File control isn't just a button, it's DIV with a table, rows, a label. I've tried making Javascript click all sorts of elements within the file attachment control but it doesn't seem to trigger the file download.
I have attached the screenshot that shows what a file attachment control is made up of.
If anyone has any ideas I'd love to hear them, thank you!!


11597iB19567D1D58F5B47.png

icon

Best answer by Albarghouthy 21 March 2019, 17:45

View original

2 replies

Userlevel 5
Badge +16
Hi,

Please see this:
https://help.k2.com/support-services/kbt154698

Thank you for that,
It was very useful. It does bear note that I had to use the following 

<script type="text/javascript">$('label[class="file-label"]').first().click();</script>

This was to prevent every file attachment control from being clicked.

Reply