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 atributevar firstNm = document.getElementById("Ime").value;// array definitionvar prviNiz = Array('Ć','Č','Š','Ž','Đ');var drugiNiz = Array('&# 262;','&# 268;','&# 352;','&# 381;','&# 272;');// replacing charactersvar 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) elementdocument.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.