-2
I would like the moment the pdf file was selected, if it comes with accent that is removed by the remove_accents function().
<tr>
<th nowrap>Arquivo PDF*: </th>
<td><input type="file" name="arquivoPDF" id="arquivoPDF" class="CampoTexto1" onchange="retira_acentos(this)"/></td>
</tr>
How do I read the file name and then pass it to the remove accents function and show on screen to the user?
if(!validaExtensaoArquivo(retira_acentos($('arquivoPDF')), "pdf")){
bootbox.alert("O arquivo referente ao campo 'Arquivo PDF' deve possuír extensão pdf.");
$('btoAlterar').disabled = false;
return false;
}
function retira_acentos(str)
{
com_acento = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
sem_acento = "AAAAAAACEEEEIIIIDNOOOOOOUUUUYRsBaaaaaaaceeeeiiiionoooooouuuuybyr";
novastr="";
for(i=0; i<str.length; i++) {
troca=false;
for (a=0; a<com_acento.length; a++) {
if (str.substr(i,1)==com_acento.substr(a,1)) {
novastr+=sem_acento.substr(a,1);
troca=true;
break;
}
}
if (troca==false) {
novastr+=str.substr(i,1);
}
}
return novastr;
}
Related: Error while removing accents
– Icaro Martins
You want to select a file on
input
and when selecting already remove accents? Before sending proback-end
?– Pedro Henrique
That’s right @Pedrohenrique ! It should show on the front screen already without the accents for the user and send to the back as well.
– João Victor Lima Rocha
@Joãovictorlimarocha, I believe it is not possible to change the name of the file in a
input.file
, but you can recover the name to use, what you intend to do?– Pedro Henrique
I need to remove the accents from the file name before uploading to the backend. @Pedrohenrique
– João Victor Lima Rocha
No way to send the file with the changed name.
– Sam
You can show the file name pro user without accents and on
back-end
only removes the accents.– Pedro Henrique
@Pedrohenrique Como?
– João Victor Lima Rocha