0
Hello my doubt is the following, I have a js function like this:
function testeCampos(elemento) {
//Recebe lista de campos para valida��o
var camposArray = new Array();
camposArray = elemento;
//Recebe campo armazenado no array
var campo, recFocu;
//Verifica se h� uma ocorrencia de erro
var faltaPre = false
//varre o Array de Campos
for (c = 0; c < camposArray.length; c++) {
//cria Objeto com o metodo DOM
campo = document.getElementById(camposArray[c]);
if (campo.value == '') {
campo.style.backgroundColor = "#eeee99";
if (faltaPre != true) {
faltaPre = true;
recFocu = campo;
}
}
else {
campo.style.backgroundColor = "white";
}
}
if (faltaPre == true) {
alert('Campo com Preenchimento obrigat\xf3rio!!!');
recFocu.focus();
return false;
}
else {
return true;
}
}
takes as parameter a textbox array and validates one by one
I am mounting the array on page_load page so:
TextBox[] aTextbox = { txtNome, TxtEndereco, TxtCEP, TxtBairro, TxtUF, TxtCidade, TxtTelefone, txtUsuario, TxtSenha };
and triggering the onClick event at Codebehind like this:
this.btnEnviar.Attributes.Add("onclick", "return testeCampos(aTextbox);");
Is there an error in my code? because it is giving error in JS
Your Textbox[] array should not be a string[] with field ids?
– Leandro Angelo
I did and the error continues string[] aTextbox = { txtNome.ID, Txtendereco.ID };
– Antonio_Sistema_de_Informacao
But I always send a textbox object, so I created the textbox array
– Antonio_Sistema_de_Informacao
Note: 0x800a1391 error - Javascript runtime error: 'aTextbox' is not set
– Antonio_Sistema_de_Informacao
Edit your question in more detail with the full page or view.
– Leandro Angelo
The idea is to scroll through textbox by textbox the first empty field it should give Focus in the blank and ready.
– Antonio_Sistema_de_Informacao
posted page, if it will not be only advocating... as for example aTextBox is a server side object... it was not written on the screen and so does not exist in the scope of javascript
– Leandro Angelo
Oops, sorry leandro updated with a git link has my registration page :(
– Antonio_Sistema_de_Informacao
Thanks leandro, get, I’ll leave my answer to members with doubt ;)
– Antonio_Sistema_de_Informacao