Re: Replacing diacritics in Javascript

Thursday, December 13, 2012

First, replace
var drugiNiz = Array('&# 262;','&# 268;','&# 352;','&# 381;','&# 272;');
with
var drugiNiz = Array('C','C','Z','S','D');

Next, replace
for(i = 0; i < 10; i++)
with
for(i = 0; i < prviNiz.length; i++)

and test again. If this doesn't fix the problem, please include a full page of HTML with some sample names so I can test my solution.

Kind regards,

James Larson

On Wednesday, December 12, 2012 5:18:37 AM UTC-5, Zagorka Martinovic wrote:
Hi all,
I need some help with my script, I'm stuck in combining two aspects of it..
I have a form where people put their first and last name, and script generates new first and last name based on first letters of their input.
Problem is when names start with čćžšđ characters which are common in my language. I want to replace them with czsd, so I colud have array from A to Z.

For thet part fetching fist character of first name I have this

var firstNm = document.getElementById("Ime").value.toUpperCase();
var validName = true;
if (firstNm == "") {
validName = false;
}
else {
var firstNum = firstNm.charCodeAt(0) - 65;
if (firstNum < 0 || firstNum > 25) {
validName = false;
}
}if (!validName) {
document.getElementById("Ime").focus();
document.getElementById("Ime").select();
return "Niste dobro upisali ime";
}

and for replacing diacritic I have this
function zamjenaZnakova(){
// fetching valuest trought ID atribute
var firstNm = document.getElementById("Ime").value;
// array definition
var prviNiz = Array('Ć','Č','Š','Ž','Đ');
var drugiNiz = Array('&# 262;','&# 268;','&# 352;','&# 381;','&# 272;');
// replacing characters
var prvi, drugi, i;
for(i = 0; i < 10; i++){
prvi = new RegExp(prviNiz[i], 'g');
drugi = drugiNiz[i];
firstNm firstNm.replace(prvi, drugi);
}
// getting back replaced text into (ID) element
document.getElementById(id).value = firstNm;
}

But I'm keep getting false return.

Any help would be nice. 

Thanks in advance :)

--
 
 

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright © 2010 Web Design | Free Blogger Templates by Splashy Templates | Layout by Atomic Website Templates

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Animals Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos Matilde futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii