2
I have the following code:
function valida_form (){
var filter_nome = /^([a-zA-Zà-úÀ-Ú0-9]|-|_|\s)+$/ ;
if(!filter_nome.test(document.getElementById("input_nome_cad").value)){
document.getElementById("input_nome_cad").value='';
document.getElementById("input_nome_cad").placeholder = "Nome inválido";
document.getElementById("input_nome_cad").focus();
document.getElementById("input_nome_cad").style.borderColor = "#ff0000";
document.getElementById("input_nome_cad").style.outline = "#ff0000";
return false;
}
}
In the code there are several interactions performed on an element with the same "ID", there is some way to call it only 1 time ?
Why not save the result of
getElementById
in a variable?– Pablo Almeida
@Pabloalmeida I am totally newb in javascript, it is possible you using the code above, expose a solution via code, pls...
– MagicHat
@Magichat, tried to use
<input id='input_nome_cad' type='text' pattern='^([a-zA-Zà-úÀ-Ú0-9]|-|_|\s)+$' title='Nome inválido' />
and define a css in case the input is invalid:#input_nome_cad:invalid { borderColor: red; outline: red; }
?– Tobias Mesquita
@Tobymosque is pq am avoiding HTML5... Can you help me with this question here (http://answall.com/questions/131579/returnr-div-stilo-anterior-ap%C3%B3s-ter-altered-style-only-with-javascrip) ? See if you can help me with this...
– MagicHat