greetings!
I have looked around, found several scripts, read about the string.replace but I still can’t pull it together.
In Bar.html I have a form (BarFrm) and it has several inputs, in the head of the page I have a validating function. In this validating function I want to set the code to replace all occurrences of latin accents the user may had written for its unaccented form:
á –> a
é –> e
í –> i
ó –> o
ú –> u
This because if Insert them to the database without the replace it will not be set as the same letter
[B]á [I]is set as[B]é
here is my function. so far it does validate all but the replace:
[code=html]
<script language=”javascript”>
function trim(str)
{
return str.replace(/^s+|s+$/g,”);
}//trim
function ValBarFrm(){
var CanCar = 0;
var Nombre, Provincia, Canton, Direccion, Caract1, Caract2, Caract3, Caract4, Caract5, Caract6, Caract7, Caract8, Caract9, Caract10, Caract11;
<!– This is the important part. I want Nombre to have its és replaced –>
Nombre = window.document.BaresFrm.Nombre;
Nombre = Nombre.replace(/é/g,”e”);
Provincia = window.document.BaresFrm.Provincia;
Canton = window.document.BaresFrm.Canton;
Caract1 = window.document.BaresFrm.Caract1;
Caract2 = window.document.BaresFrm.Caract2;
Caract3 = window.document.BaresFrm.Caract3;
Caract4 = window.document.BaresFrm.Caract4;
Caract5 = window.document.BaresFrm.Caract5;
Caract6 = window.document.BaresFrm.Caract6;
Caract7 = window.document.BaresFrm.Caract7;
Caract8 = window.document.BaresFrm.Caract8;
Caract9 = window.document.BaresFrm.Caract9;
Caract10 = window.document.BaresFrm.Caract10;
Caract11 = window.document.BaresFrm.Caract11;
Direccion = window.document.BaresFrm.Direccion;
var Enviar = new Boolean(true);
if(trim(Nombre.value) == ”)
{
alert(‘Tienes que poner el nombre del Bar’);
Nombre.focus();
Enviar = false;
}
else if(trim(Provincia.value) == ”)
{
alert(‘Seria muy util que pusieras la provincia’);
Provincia.focus();
Enviar = false;
}
else if(trim(Canton.value) == ”)
{
alert(‘Hace falta el canton, como ejemplo: Escazu, San Pedro’);
Canton.focus();
Enviar = false;
}
else if(trim(Direccion.value) == ”)
{
alert(‘Si no pones la direccion no sabremos como llegar…’);
Direccion.focus();
Enviar = false;
}
if(trim(Caract1.value) != ”)
{
CanCar += 1;
}
if(trim(Caract2.value) != ”)
{
CanCar += 1;
}
if(trim(Caract3.value) != ”)
{
CanCar += 1;
}
if(trim(Caract4.value) != ”)
{
CanCar += 1;
}
if(trim(Caract5.value) != ”)
{
CanCar += 1;
}
if(trim(Caract6.value) != ”)
{
CanCar += 1;
}
if(trim(Caract7.value) != ”)
{
CanCar += 1;
}
if(trim(Caract8.value) != ”)
{
CanCar += 1;
}
if(trim(Caract9.value) != ”)
{
CanCar += 1;
}
if(trim(Caract10.value) != ”)
{
CanCar += 1;
}
if(trim(Caract11.value) != ”)
{
CanCar += 1;
}
if (CanCar < 2){
alert(‘Tienes que poner al menos 2 caracteristicas del lugar’);
if(Caract1.value!=”){Caract2.focus();} else {Caract1.focus();}
Enviar = false;}
return Enviar;
}//Revisar
</script>
but the replace after the comments doesnt work.
Help please ?
thanks!