0

I need it to be under not next to the button. Is there any easy way to do that?

<input type="file" size="45"> 

2 Answers2

1

How about a solution like this

<input type="file" id="selectedFile" style="display: none;" onchange="document.getElementsByTagName('p')[0].innerHTML=this.value;"/>
<input type="button" value="Browse..." onclick="document.getElementById('selectedFile').click();" />
<p>no file chosen</p>

An example: https://jsfiddle.net/366tjfvn/1/

ref: How to hide text field in Html File Upload

Updated thanks to: Ismael Miguel

Community
  • 1
  • 1
Vangel Tzo
  • 8,885
  • 3
  • 26
  • 32
-1

Add the following code snippet:

Html:

@using (Html.BeginForm("FileUpload", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
                @Html.AntiForgeryToken()
                <label style="width: 33px; display: inline-block;">Path : </label>
                <input type="text" id="UploadTextBox" readonly="readonly" style="display: inline-block; margin-left: 5px; width: 300px; height: 18px; background-color: white;" />
                <input type="file" id="BtnBrowseHidden" name="files" style="display: inline-block; margin-left: 15px;" />
                <label for="BtnBrowseHidden" id="LblBrowse" style="display: inline-block; margin-left: 15px;">
                    Browse
                </label>
                <input type="submit" id="BtnUpload" value="Upload" style="display: inline-block; margin-left: 15px;" />
            }
        <div>
            <label id="ErrorMessage" style="display: none; text-align: center; width: 200px; margin-left: 345px;"></label>
        </div>

Jquery code:

<script type="text/javascript">
    $(document).ready(function () {
        $('#BtnBrowseHidden').hide();
        $("#BtnBrowseHidden").change(function () {
            var Value = $(this).val();
            $('#UploadTextBox').val(Value);

            if (Value != "") {
                var extesion = /[^.]+$/.exec(Value);
                if (extesion[0] != "xlsx" && extesion[0] != "xls") {
                    //Please upload Excel file.
                    $("#ErrorMessage").html("Please upload Excel file.");
                    $("#ErrorMessage").css('color', 'red');
                    $("#ErrorMessage").show();
                    document.getElementById("BtnUpload").disabled = true;
                }
                else {
                    $("#ErrorMessage").html("");
                    $("#ErrorMessage").hide();
                    document.getElementById("BtnUpload").disabled = false;
                }
            }
            else {
                    $("#ErrorMessage").html("No File choosen.");
                    $("#ErrorMessage").css('color', 'red');
                    $("#ErrorMessage").show();
                 }
            return false;
        });
});
</script>
Prasad Shigwan
  • 520
  • 5
  • 14