I am working on a web project where I have an HTML input for uploading a picture to my FTP server. I want to use JavaScript to detect changes on my upload button. This is the code in my CSHTML file:
@using (Html.BeginForm("UploadFile", "Upload", FormMethod.Post, new {
enctype = "multipart/form-data" }))
{
<input id="uploadFile" placeholder="No file..." disabled="disabled" />
<div class="fileUpload btn btn-primary">
<span>Browse</span>
<input id="uploadBtn" type="file" class="upload" />
</div>
<input type="submit" title="OK" />
}
Here is my JavaScript code:
<head>
<script type="text/javascript" language="javascript">
document.getElementById("uploadBtn").onchange = function ()
{
document.getElementById("uploadFile").value = this.value;
};
</script>
</head>
However, when I run the code, I receive the following error message:
0x800a138f - JavaScript runtime error: Unable to get property 'onchange' of undefined or null reference
I have tested the HTML and JS in a fiddle and they work fine, so it seems that there may be some compatibility issues between Razor syntax and JavaScript. Any suggestions on how to resolve this?