JavaScript jQuery mousedown not working on file submit button jquery mousedown not working,jquery mousedown not working chrome,jquery

I have a contact form (Drupal Webform) that includes a file upload that creates a form containing this markup (i have stripped the name, size and id attr. in this example):

<div class="form-managed-file">
    <input type="file" class="form-file">
    <input type="submit" value="Upload" class="form-submit ajax-processed">
    <input type="hidden" value="0">
</div>

I would like for the upload button to be clicked automatically on file upload. I have done this in the past with a function like this but it is not working on this one:

$('.webform-client-form').on('change', 'input.form-file', function() {
    $(this).next('input[type="submit"]').mousedown();
}); 

However these are working on this form:

$('.webform-client-form').on('change', 'input.form-file', function(){
    $(this).next('input[type="submit"]').css("background", "red");
    alert($(this).next('input[type="submit"]').val());
});

The first gives the button a red background. The second alerts "Upload". Why is the mousedown not working? I have also used click() trigger("click") and trigger("mousedown") but none of them are clicking the upload button. I am using jQuery 1.10.

Answer:1

You're only triggering mousedown. You also need to capture the trigger and act accordingly, such as:

$('.webform-client-form').on('mousedown', 'input[type="submit"]', function() {
    alert ("mousedown");
});

If I am not wrong, what you're trying to do is to submit the form when the .change is triggered. If that's the case, you might as well submit the form within your .change handler, such as:

$('.webform-client-form').on('change', 'input.form-file', function() {
    $('.webform-client-form').submit();
});
Answer:2

I am trying start with promises and angularJS. My backend is returning the correct values, but my html view doesn´t show my table with the data returning from backend. What is wrong here? Here is ...

I am trying start with promises and angularJS. My backend is returning the correct values, but my html view doesn´t show my table with the data returning from backend. What is wrong here? Here is ...

  1. angular updating view
  2. angular view not updating
  3. angular view not updating on model change
  4. angular view not updating until click
  5. angular view not updating after subscribe
  6. angular view not updating on scope change
  7. angular view not updating after model changes
  8. angular 6 view not updating
  9. angular 5 view not updating
  10. angular 4 view not updating
  11. angular array not updating view
  12. angular 7 view not updating
  13. angular observable not updating view
  14. angular setvalue not updating view
  15. angular 8 view not updating
  16. angular model not updating view
  17. angular ngfor not updating view
  18. angular 2 view not updating
  19. angular component view not updating
  20. angular service not updating view

I need to set my xAxis the following values: Values : 63,80,100,125,160,200,250,315,400,500,630,800,1000,1250,1600,2000 The values currently displayed: Values currently: 125,250,375,500,625,750,875,...

I need to set my xAxis the following values: Values : 63,80,100,125,160,200,250,315,400,500,630,800,1000,1250,1600,2000 The values currently displayed: Values currently: 125,250,375,500,625,750,875,...

Suppose we have the following pure function: const HeaderComponent = () => ( <h1> Title <h1> ) export default HeaderComponent Now I need to receive the new title from props, so we ...

Suppose we have the following pure function: const HeaderComponent = () => ( <h1> Title <h1> ) export default HeaderComponent Now I need to receive the new title from props, so we ...

I got the following input Wed, 08 Feb 2017 10:09:19 GMT form server. I've been trying to parse this string with momentjs but couldn't find format that will parse the GMT right. and if i'm not ...

I got the following input Wed, 08 Feb 2017 10:09:19 GMT form server. I've been trying to parse this string with momentjs but couldn't find format that will parse the GMT right. and if i'm not ...

  1. parsing date string python
  2. parsing date string in javascript
  3. parsing date string in java 8
  4. parsing date string in java
  5. parsing date string js
  6. parsing date string in c#
  7. parsing date string format
  8. parsing string date
  9. error parsing date string
  10. error parsing date string jira
  11. perl parsing date string
  12. parsing date into string
  13. parsing date into string javascript
  14. jira api error parsing date string
  15. python parsing datetime string
  16. parsing java.util.date string