1
On my form, there’s a textarea
and I would like to add, every 10 characters typed, the character X
, without submitting the page.
Example:
AAAAAAAAAA**X**BBBBBBBBBB**X**EEEEEEEEEE**X**12345678....
As the user was typing, would insert every 10 characters. In this case, I do not need to mask, but rather add the X
to the 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 to count characters and gave a basic change, which only adds +1 every 10 characters typed, value defined in input#tamanho_codbarras
.
The goal is to break down the information typed on the next screen, with the PHP function explode
. In case, my break control would be by character X
, using the example:
AAAAAAAAAA
BBBBBBBBBB
EEEEEEEEEE
12345678
What is your knowledge of Javascript? And could you say what is the purpose of inserting this character in the middle of the text?
– Woss
Eduardo, share with us what you have tried. Edit your question and enter the
HTML
and theJavascript
that used.– Caique Romero
If you just want to split this text in PHP, I have to say that this solution is bad. Mainly by interfering with the text typed by the user. Imagine you typing a comment here on the site and suddenly it starts to appear
X
in the middle of your text? Extremely inappropriate. You can split the text every 10 characters with PHP without needing it, but you won’t be able to answer that question.– Woss
Anderson, let me summarize for you. I have a system in which loads a page only with an input text for the user to read the barcode and Submit is automatic. The user has bad internet, which makes the page load take time. I came up with the idea of leaving a textarea open, as if it were a Powerpoint or excel, and the same read as many codes you want and in the end send, however, the barcode, does not have a character for 'break control', so I posted the question.
– Eduardo
Okay, but you do realize how uncomfortable this can be, right? If you really want this to be done on the client side, use the character
\n
instead ofX
, because it will not generate discomfort and will be visually more pleasant. Then, it will be necessary to analyze how the insertion of the value in the textarea by the bar code reader. Depending on how, not all answer codes will work, as it will depend on the event handled in Javascript. And even if you do this in JS, also remember to treat the information in PHP. Never trust your user data.– Woss
In the case of X, it was also an example. I’m thinking of using a semicolon. I have two readers on hand and testing. One has auto enter and the other inserts " n" after reading. I’ve done the negotiations in PHP. Really, we can not trust the user, but in this case, we have done everything, but they have a serious problem with the internet, and as I can not lose the client... Even if he type anything, the next screen has a fine-toothed comb that validates the information. I thank you for your help and attention.
– Eduardo