I have the following JavaScript:
function validaCaracteres(strToReplace) {
strSChar = "áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ";
strNoSChars = "aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC";
var newStr = "";
for (var i = 0; i < strToReplace.length; i++) {
if (strSChar.indexOf(strToReplace.charAt(i)) != -1) {
newStr += strNoSChars.substr(strSChar.search(strToReplace.substr(i, 1)), 1);
} else {
newStr += strToReplace.substr(i, 1);
}
}
return newStr.replace(/[^a-zA-Z 0-9]/g, '').toUpperCase();
}
The purpose of this is to remove special characters at typing time, special characters, accents, and if the String is a lowercase letter, return it at typing time.
However, the following error occurs, it works differently in certain Browsers, such as IE, it does not allow placement within the String, sending to the last position of the String, does not allow the reprint of the Text.
I need the text to be typed wrong if I have the option to re-edit it.
Is there any way to do this?
I'm calling this function this way:
<h:inputText value="#{manBean.manVO.field}"
onblur="this.value = validaCaracteres(this.value);"
onkeyup="this.value = validaCaracteres(this.value);"
onkeydown="this.value = validaCaracteres(this.value);"/>
Is there any other way to do this, and can I use the reprint of the text?
Thank you in advance!