4
I managed to make simple mask for telephone fields, zip code, R$, etc.
But I wanted a mask to detect and automatically format a field for CPF or CNPJ in the same input, but preferably pure html/javascript, without plugins, at most using as conditional a radio button or dropdown.
It is possible to do this without using any plugin or I am asking too?
Adding: I know the subject is very repetitive, and I even found a lot of documentation about it, but always using external plugins, I would like to be able to do something totally portable, that doesn’t need additional files and that works offline.
I made the generic mask using the next function:
function formatar(mascara, documento){
var i = documento.value.length;
var saida = mascara.substring(0,1);
var texto = mascara.substring(i)
if (texto.substring(0,1) != saida){
documento.value += texto.substring(0,1);
and later in the inputs the events: onkeypress="formatar('###.###.###-##', this)"
and etc
I wanted a function or script that detected the number of digits inserted to configure the mask as CPF or CNPJ.
java web? What have you done so far of this page?
– user28595
Do you know Primefaces? Everything is ready there.
– Giuliana Bezerra
Edit the question and add relevant portion of the page. Or Do you want someone willing to help you to have to download your entire project from the drive? Make life easier for anyone who will help you, edit the question by adding the page code where you want to insert these filters.
– user28595
This is not java, it’s javascript.
– user28595
Sorry... totally beginner, this is my first file with anything other than plain text and fields/tables.
– Rafael