Guest User

Untitled

a guest
Aug 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. clear file input field using jQuery [closed]
  2. $.fn.clearForm = function() {
  3. return this.each(function() {
  4. var type = this.type, tag = this.tagName.toLowerCase();
  5. if (tag == 'form')
  6. return $(':input',this).clearForm();
  7. if (type == 'text' || type == 'password' || tag == 'textarea')
  8. this.value = '';
  9. else if (type == 'checkbox' || type == 'radio')
  10. this.checked = false;
  11. else if (tag == 'select')
  12. this.selectedIndex = -1;
  13. });
  14. };
  15.  
  16. <section><label for="productimg">Picture<br></label>
  17. <div><input type="file" id="productimg" name="productimg"></div>
  18. </section>
  19.  
  20. $('#myform')[0].reset();
  21.  
  22. $('#form_id').each(function(){
  23. this.reset();
  24. });
  25.  
  26. var id=$(this).attr('id');
  27. $(this).replaceWith("<input type='file' id='"+id+"' />");
  28.  
  29. jQuery.fn.reset = function(){
  30. $(this).each (function() { this.reset(); });
  31. }
Add Comment
Please, Sign In to add comment