How to clear the file upload control value using jQuery / JavaScript

Category > ASP.NET || Published on : Monday, February 8, 2016 || Views: 10864 || clear the file upload control value using jQuery / JavaScript


Introduction

Here Pawan Kumar will explain how to clear the file upload control value using jQuery / JavaScript

Description

In previous post I have explained Create a QR Code with a Logo in ASP.Net C#, jQuery to Check UnCheck All CheckBoxes in Repeater in Asp.Net C#, Check UnCheck All CheckBoxes in Asp.Net GridView using jQuery, Asp.Net Serialization & Deserialization with C#.Net, jQuery to Dynamically Change or Set Placeholder Text in Asp.Net TextBox, jQuery to Validate File Type and Size before Uploading through Asp.Net FileUpload Control, and many more articles.

Now I will explain How to How to clear the file upload control value using jQuery / JavaScript

So follow the steps to learn How to clear the file upload control value using jQuery / JavaScript

jQuery:-

<html>
<head>
    <title></title>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.js" type="text/javascript"></script>
    <script type="text/javascript">
function clear_html(id) {
    $('#'+id).html($('#'+id).html());
}
    </script>
    </head>
        <body>

            <div id="myDiv1">
                <input type="file" id="upload1" />
                <input type="button" value="Clear" onclick="clear_html('myDiv1')" />
            </div>

        </body>
</html>

Javascript:-

<html>
<head>
    <title></title>
    <script type="text/javascript">
        function clear_html(id) {
            var element = document.getElementById(id);
            element.innerHTML = element.innerHTML;
        }
    </script>
</head>
<body>

    <div id="myDiv1">
        <input type="file" id="upload1" />
        <input type="button" value="Clear" onclick="clear_html('myDiv1')" />
    </div>

</body>
</html>

 

Conclusion:

So, In this tutorial we have learned, How to clear the file upload control value using jQuery / JavaScript

Download Source Codes