Use Javascript to clear (reset) the value of the INPUT element of the file type, using criptinput

Source: Internet
Author: User

Use Javascript to clear (reset) the value of the INPUT element of the file type, using criptinput

I have answered this question in StackOverflow before, and now I am sorting it out in my Blog.

Due to security restrictions, the script cannot set its value at will, so it cannot be reset with attributes like other form input fields.

There are three methods to reset the value of a file domain.

This article analyzes the browser compatibility and advantages and disadvantages of these three methods, and provides a perfect comprehensive solution code and Demo.


There are three methods to reset the file domain:

By combining method 1 and method 3, you can be compatible with all browsers.

The Javascript function code is as follows:

    function clearInputFile(f){        if(f.value){            try{                f.value = ''; //for IE11, latest Chrome/Firefox/Opera...            }catch(err){            }            if(f.value){ //for IE5 ~ IE10                var form = document.createElement('form'), ref = f.nextSibling;                form.appendChild(f);                form.reset();                ref.parentNode.insertBefore(f,ref);            }        }    }

View demo: http://jsbin.com/muhipoye/1/






How to use javascript to clear the value of type = text in input

I don't understand what I want to achieve. According to my understanding, there are two kinds of conjecture:
The first conjecture: when a user attempts to enter an invalid value in the text box, the user is not allowed to input, that is, the input is ineffective.

The second conjecture: before submitting a form, I want to clear all the text boxes and then submit them again?

I don't know which one are you talking about?

Clear the text box with javascript, and restore the default value in the text box

For example, <input type = "text" value = "$ {a}" id = "xx"/>
<Input type = "button" value = "go" onClick = "f ()">
<Script type = "text/javascript">
Function f (){
Var xx = document. getElementById ("xx ");
Xx. value = "";
}
</Script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.