In my form, you have textarea
and would like to add the character X
, without submitting the page, every 10 characters typed.
Example:
AAAAAAAAAA**X**BBBBBBBBBB**X**EEEEEEEEEE**X**12345678....
As the user typed in, he would enter every 10 characters. In this case, I do not need to mask, but rather add X
to content.
Has anyone seen or done anything like this?
function mostrarResultado(box, campo_msg_contagem, campo_volumes_hidden) {
var conteudo = document.getElementById('conteudo').value;
var campo_caracteres = box.length;
var tamanho_total_codbarras = document.getElementById('tamanho_codbarras').value;
var resultado = 0;
if (campo_caracteres > tamanho_total_codbarras) {
resultado = Math.round(campo_caracteres / tamanho_total_codbarras);
document.getElementById(campo_msg_contagem).innerHTML = "Lidos = " + resultado + "";
document.getElementById(campo_volumes_hidden).value = resultado;
} else {
document.getElementById(campo_msg_contagem).innerHTML = "";
}
}
<form name="form1" id="form1" action="teste.php" method="post">
<textarea cols="50" id="conteudo" name="conteudo" rows="30" onkeyup="mostrarResultado(this.value, 'msg_contagem', 'volumes_hidden');"></textarea><br />
<span id="msg_contagem" style="font-family:Georgia;"></span><br />
<input type="hidden" id="tamanho_codbarras" name="tamanho_codbarras" value="10" />
<input type="hidden" id="volumes_hidden" name="volumes_hidden" value="" />
<input type="submit" /><br>
</form>
In this case, I took this function of counting characters and gave a basic change, which only adds +1 to every 10 characters entered, value set in input#tamanho_codbarras
.
The goal is to break down the typed information on the next screen, with PHP explode
function. In this case, my break control would be by the character X
, using the example:
AAAAAAAAAA
BBBBBBBBBB
EEEEEEEEEE
12345678