Creating File Input for a HTML Form

The <input type=”file” tag is used to upload a file on a Web Page. When you use the <input type=”file”> tag, you also need to set the enctype attribute by providing the value as multipart/form-data.

Let’s do the following steps to create file input for a form:


<!DOCTYPE html>
<html>
<head>
    <title> Creating File Input</title>
    <script language=”Javascript”>
        Function ShowMessage()
            {
                alert(“File uploaded successfully”);
}
    </script>
</head>
<body>
<center>
    <h1>Uploading a File</h1><br>
    <form enctype=”multipart/Frm-data”  action=”” method=”post”>
        <input type=”file” name=”filename” value=”Upload” OnClick=”ShowMessage()” /><br><br>
    <input type=”button” value=”Restore Text” OnClick=”restoretext()” />
    </form>
</center>
</body>
</html>

Save the document with the name CreatingFileInput.html and open on browser.