Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear file input field using jQuery [closed]
- $.fn.clearForm = function() {
- return this.each(function() {
- var type = this.type, tag = this.tagName.toLowerCase();
- if (tag == 'form')
- return $(':input',this).clearForm();
- if (type == 'text' || type == 'password' || tag == 'textarea')
- this.value = '';
- else if (type == 'checkbox' || type == 'radio')
- this.checked = false;
- else if (tag == 'select')
- this.selectedIndex = -1;
- });
- };
- <section><label for="productimg">Picture<br></label>
- <div><input type="file" id="productimg" name="productimg"></div>
- </section>
- $('#myform')[0].reset();
- $('#form_id').each(function(){
- this.reset();
- });
- var id=$(this).attr('id');
- $(this).replaceWith("<input type='file' id='"+id+"' />");
- jQuery.fn.reset = function(){
- $(this).each (function() { this.reset(); });
- }
Add Comment
Please, Sign In to add comment