Replace ÅÄÖ in a textarea!
Hola!I need to replace ÅÄÖ in a textArea!
This works fine on both browsers at PC, but I don\'t get this to work at NS on Mac.
I get some texts from a DB where I already replaced the swedish chars \"ÅÄÖ\".
These texts is Stored in an array in the JS-code. I switch between these text through a select-box and applys into a textarea. But I can\'t get it right in the textarrea
I have try this:
function replaceChar(string,text,by)
{
// Replaces text with by in string
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0))
{
return string;
}
var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength)))
{
return string;
}
if (i == -1)
{
return string;
}
var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)
{
newstr += replaceChar(string.substring(i+txtLength,strLength),text,by);
}
return newstr;
}
/*
function decodeSwedishChars(text)
{
text = replaceChar(text, \'[xax]\', \'å\');
text = replaceChar(text, \'[xaex]\', \'ä\');
text = replaceChar(text, \'[xox]\', \'ö\');
text = replaceChar(text, \'[xAx]\', \'Å\');
text = replaceChar(text, \'[xAEx]\', \'Ä\');
text = replaceChar(text, \'[xOx]\', \'Ö\');
return text;
}
*/
function decodeSwedishChars(text)
{
text = replaceChar(text, \'[xax]\', \'å\');
text = replaceChar(text, \'[xaex]\', \'ä\');
text = replaceChar(text, \'[xox]\', \'&oring;\');
text = replaceChar(text, \'[xAx]\', \'Å\');
text = replaceChar(text, \'[xAEx]\', \'Ä\');
text = replaceChar(text, \'[xOx]\', \'&Oring;\');
return text;
}
The \'[xAx]\',for eg, is my own ecoding for swedish charcters in the DB.
So before i apply the text into the textarea I call the decode-method
<script language=\"javascript\">
var texts = new Array(1);
var text0 = new Array(2);
text0[0] = \"2001-05-21 16:38:18.11\";
text0[1] = decodeSwedishChars(\"<b>V[xaex]lkommen</b>\");
texts[0] = text0;
function applyText()
{
var form = window.document.forms[\"text_form\"];
//alert(\"applyText: \" + form.oldtext.selectedIndex);
for(var i = 0; i < texts.length; i++)
{
if(form.oldtext.options[ form.oldtext.selectedIndex ].value == texts[i][0])
{
form.text.value = texts[i][1];
}
}
}
</script>
So if any one have an ide let me know!
Best regards!
Fredrik Andersson