-1

I call:

$('#encoderPreset').trigger('click');

on:

<input id="encoderPreset" type="file" name="name" style="display: none;" accept=".EPR" />

to open a file dialog. The problem is that the code keeps running and I need to use the resulting file path directly after. The only "fix" I found is to place an alert because then the code will pauze.

Know that the dialog is called inside a function that is called by a button.

I found a lot of similar questions but none of them seem to work for me.

4b0
  • 21,981
  • 30
  • 95
  • 142
Moodz
  • 7
  • 2
  • 2
    Why can't use use change event on the file input instead? Please provide a [mcve] – charlietfl Apr 20 '17 at 11:33
  • Handle the rest of the function inside the dialog box which is getting the value.. and also provide a sample of how you have coded it. – Jones Joseph Apr 20 '17 at 11:34
  • I think you should break your code in functions, and use callback to continue the execution... Remember that javascript is monothread, if you stop it, you will stop ALL javascript process of the page. – Rafael Biriba Apr 20 '17 at 11:51
  • you don't want to *pause execution* you need to handle the async call. – Liam Apr 20 '17 at 11:53

1 Answers1

1

No need to pause java-script

just add code which you want to execute after file selection into following function:

$("#encoderPreset").change(function() {            
        ...
});
Sharad Kale
  • 971
  • 1
  • 7
  • 19