I'm having trouble validating a field by clicking the incluir
button, so I click on incluir
gives this error below:
Unable to get 'value' property value: object is null or undefined.
This error appears in this line of the function:
(document.getElementById("<%=txtEmail.ClientID%>").value == "")
The file containing the function has already been instantiated in the html code:
<script src="Javascript/validacao.js" type = "text/javascript" > < /script>
Code view where it contains incluir_click
and its Page_Load
returning the js function:
Protected Sub Page_Load(sender As Object, e As EventArgs)
btnIncluir.Attributes.Add("onclick", "return valida_campos()")
End Sub
E-mail validation function in .js file:
function valida_campos() {
if (document.getElementById("<%=txtEmail.ClientID%>").value == "") {
alert("Email obrigatório");
document.getElementById("<%=txtEmail.ClientID%>").focus();
return false;
}
var emailPat = /^(\".*\"|[0-9-A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var emailid = document.getElementById("<%=txtEmail.ClientID%>").value;
var matchArray = emailid.match(emailPat);
if (matchArray == null) {
alert("O Email esta no formato incorreto. Tente novamente.");
document.getElementById("<%=txtEmail.ClientID%>").focus();
return false;
}
}