I have a function in Javascript, and every time I put it in the function, I want it not to enter if the value has null, because it is giving error. It only needs to get in the function if attachment is other than null. Here's how I'm doing:
$(function () {
if (document.getElementById("Anexo").value != "" || document.getElementById("Anexo").value != undefined || document.getElementById("Anexo").value != null) {
$('#<%=Anexo.ClientID %>').change(function () {
var f = this.files[0]
if (f.size > 8388608 || f.fileSize > 8388608) {
alert("Tamanho excede o limite permitido.")
this.value = null;
}
})
}
});
In any way I put it, it always returns the error in this line:
$ ('# '). change (function () {
If the Annex is filled it does not return an error, but it may happen to be empty. And it can not return error, so I'm trying to use the if.
Editing: After many attempts, I came up with the following error:
Object reference not set to an instance of an object. What happens in this line: $ ('# <% = Attachment.ClientID% >'). change (function () {
I use the Asp.net C # language. Attachment is a FileUpload component, this error occurs only when the component is empty, so it would need to check if it is null to perform the function.
Editing: I've tried putting it in a variable, like this:
var label = document.getElementById("<%=Anexo.ClientID%>");
When I declare in the variable, then it gives me the error in this line, and the same error as:
Object reference not set to an instance of an object.