Parse and clear the path value of the File control using JS

Source: Internet
Author: User

1. How to use a script to modify the fileupload Control Value,

In the development environment vs2005, when uploading a file, you need a Cancel button to clear the value of type = file, and there are multiple file controls on this page.

This is troublesome because the file value itself cannot be modified using scripts (security considerations)

Method 1 ). use the script to move the input of this file to a form, and then call reset. If there are multiple such inputs, you must move them again. I will not use this method because it is correct. net developers

It means you get used to a page where all the controls of a form are located.

Method 2). This method is a bit speculative, that is, it is called in the script.
Var fileup = document. getElementById (fileid );
Fileup. outerHTML = fileup. outerHTML; this ie is related to the script processing and display mechanism.

Method 3 ). this is mainly taken into account when solving the ff problem. In fact, a file with the same id is re-generated. Note that the name must be assigned a value here, otherwise, it is difficult to submit it to the server for acceptance.

During Normal project development, the file upload function is available. Generally, the frontend uses JS to determine whether the file to be uploaded belongs to the specified file type. If not, the control value is cleared! (You can also leave it empty)

There is one way to easily clear the value of the file upload component. The Code is as follows:
Var file = document. getElementById ("form1: fileupload ");
File. outerHTML = file. outerHTML

The above method can be used in IE
To be compatible with FireFox, we use the following method to clear the value of the fileupload control:
<Span id = 'uploadspan '>
<Input type = "file">
</Span>
<Script language = "JavaScript">
Var html = document. getElementById ('uploadspan '). innerHTML;
Function resetFile (){
Document. getElementById ('uploadsize'). innerHTML = html;
}
</Script>
In this way, all browsers support

Related Article

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.