Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I call the remove button of temporary uploaded file programmatically using JavaScript?

enter image description here

I want to clear the form fields when the condition changes. I've done all the form fields exept the temporary uploaded file.

Can I call the remove function? If yes, Where is it?

share|improve this question
    
Why don't you just .trigger( "click" ) on that button? This is an universal jQuery method, but I see no reason for it to fail for you. – Mołot Sep 8 '14 at 14:38
up vote 1 down vote accepted

Easiest way to do is what @Molo mentioned in his comment.

$('#element_id').trigger("click"); OR $('.element_class').trigger("click");
$('#element_id').trigger("mousedown"); OR $('.element_class').trigger("mousedown");

Or you could, reset the .html() of the upload element

$('#'+id).html($('#'+id).html()); OR  $('.'+class).html($('.'+class).html());

JavaScript into Drupal can be done in various ways, you could reference your javaScript file in your theme's info file or you override the drupal_add_js function in template.php and add your JavaScript.

For more Information on how to put JavaScript into Drupal see this or this and these (module or module) could also be handy. This article explains how to programmatically submit a form in Drupal.

Here is a good tutorial, how to add your JavaScript to Drupal https://www.drupal.org/node/756722

share|improve this answer
    
You can even shorten that to $('#element_id').click(); – Clive Sep 8 '14 at 15:57
    
@Clive could do, I went for trigger because its the new comer in JQuery, very very slightly faster performance wise. What I like the most about trigger is supplying the event-type as argument. – Raf Sep 8 '14 at 16:15
    
@Raf, the .trigger("click") event not working but .trigger("mousedown") works correctly. – John Croneh Sep 13 '14 at 10:14
    
@JohnCroneh, glad your problem is resolved, last step, kindly mark your question as resolved. – Raf Sep 13 '14 at 20:42
    
@Raf, Sorry for the delay. – John Croneh Sep 15 '14 at 5:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.