1
Good evening, you guys, I made a javascript to fix a natural person registration in order to create the pattern Name and Surname, for example, João da Silva.
I got what I wanted when the user typed everything down. However, if the user type everything in high box (JOÃO DA SILVA) javascript does not fix and leaves everything in high box even. I would also like it corrected if it was typed also in high box, in case the user forget the CAPSLOCK turned on.
function formatanome(nome){
var letra, tamanho;
tamanho = nome.length;
for (var i=0; i<tamanho; i++)
{
letra = nome.charAt(i);
if (letra== " ")
if ((i+1)<tamanho)
{
letra = nome.charAt(i+1).toUpperCase();
nome = nome.substring(0, i+1);
nome += letra;
nome += document.getElementById("nome").value.substring(i+2, tamanho);
}
}
if (tamanho>0)
{
letra = nome.charAt(0).toUpperCase();
nome = nome.substring(1, tamanho);
nome = letra + nome;
}
document.getElementById("nome").value = nome;
}
<html>
<script type="text/javascript" src="js.js"></script>
<form name="dispositivo">NIP<input id="nip" type="text" size="8" onblur="inteiro()"/>
ID<input id="resultado" type="readonly" size="8" />
NOME<input id="nome" type="text" size="40" onblur="formatanome(this.value)"/>
</form>
the difficulty is to leave the
da
minuscule– user60252
https://i.stack.Imgur.com/jx7Ts.png
– user60252
If an answer solved your problem mark it as acceita, see how in the comment link above and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252
Using a Regex would not solve your problem in a simpler and more streamlined way?
– Braytiner