0

I am currently using a fairly simple plugin within WordPress to upload a file. Users upload the file through the file input type. After that, the value is stored in the hidden wcpa_file_hidden input through jQuery.

<input type="file" id="file-1616666375492" class="photoupload wcpa_ajax_upload wcpa_file_custom " name="file-1616666375492" required="required"/>

<input type="hidden" class="wcpa_file_hidden" name="file-1616666375492_ajax" value="">

I am trying to get the value upon change. But unfortunately the change is not detected.

$('.wcpa_file_hidden').change(function() { 
    alert('TEST');
});

Any ideas?

  • Change only occurs when user removes focus. There is no way to focus a hidden input so there is no change event ever triggered. Why would you expect one? – charlietfl Mar 25 '21 at 11:30
  • Explain the higher level problem you want to solve in more detail – charlietfl Mar 25 '21 at 11:32
  • 2
    @charlietfl Are you sure? I think change should be called before blur in most cases. In this question it's the "the value is stored in the hidden wcpa_file_hidden input through jQuery" that sounds suspect to me. Setting an inputs value through JS will not trigger the change event. – DBS Mar 25 '21 at 11:33
  • *But unfortunately the change is not detected* - how exactly are you setting the value? *"stored through jquery"* - changes to values via code do not raise events. You need to do `$(".wcpa_file_hidden").val("new_value").trigger("change")` if you want a change event raised. I'm sure this has been asked multiple times before... so much fluff on SO these days that finding the answer means you need to know the answer to know what to find... https://stackoverflow.com/a/13396621/2181514 – freedomn-m Mar 25 '21 at 11:44

0 Answers0