2
I’m having trouble validating a field by clicking the button incluir
, so I click on incluir
gives this error below:
Cannot get value from 'value' property: the object is null or undefined.
This error appears in this function line:
(document.getElementById("<%=txtEmail.ClientID%>").value == "")
The file containing the function has already been instantiated in html code:
<script src="Javascript/validacao.js" type = "text/javascript" > < /script>
Code view where contains the incluir_click
and your Page_Load
returning the function js:
Protected Sub Page_Load(sender As Object, e As EventArgs)
btnIncluir.Attributes.Add("onclick", "return valida_campos()")
End Sub
Email validation function in file . js:
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;
}
}