Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing characters with accents (french characters)

Status
Not open for further replies.

kryles

Programmer
Nov 12, 2007
3
CA
Hi, I am getting textbox values after the user clicks a button. The textboxes are named text00,text10,text20 etc until text200

What I want to do is take the value of the character and see if it falls between 00192 and 00253 (like Á is 00193).

This is my code:
Code:
if((String.fromCharCode(document.form1["text"+i+"0"].["charAt("+j+")"].value) > 191) && (String.fromCharCode(document.form1["text"+i+"0"].["charAt("+j+")"].value) < 253))
{
   alert("testing special chars");
  
   switch(String.fromCharCode(document.form1["text"+i+"0"].charAt([""+j+""]).value))
  {
     case 192:
     case 193:
     case 194:
     case 195:
document.form1["text"+i+"0"].charAt([""+j+""]).value = 'A';
break;
   }
}
I never get in the if statement to see my alert. Any suggestions woul dbe very much appreciated
 
[1] Cannot decipher meaning of form1[...]. If you mean form of name "form1" and element of name "text<i>0" for some i, it should be
[tt]document.form1.elements["text"+i+"0"][/tt]

[2] If you want to relace à by A in the value, you can simply use replace function with regexp. It should not need to loop through each char etc. Beside the last statement for replacing character is not correct.
[tt]
var oelem;
oelem=document.form1.elements["text"+i+"0"]; //for some i
oelem.value=oelem.value.replace(/\xc3/g,"A");
[/tt]
[3] For more character change with no definite code corresponding pattern, do it successively for each of them.
 
okay if I do it that way, will see teh change on an alert right after? I still get the accented character.


Code:
var ch = document.form1["text"+i+"0"];
ch = ch.value.replace(/\xc3/g,"A");
alert(ch);

I also did
Code:
var ch = document.form1["text"+i+"0"];
ch = ch.value.replace(/\x0193/g,"A");
alert(ch);

since 00193 is what i'm typing for Á in the test.
 
There isn't such a thing as \x0193 for that A-thing. Either you do \xc3 or \u00c3.
 
Okay so I have it working for each individual. It does not seem to like me running them through though as a group

Code:
for(i=0;i<20;i++)
{
var len = document.form1["text"+i+"0"].value.length;

if (len > 0 )
{
   var ch = document.form1["text"+i+"0"];
   ch = ch.value.replace(/\u00C0/g,"A"); // A A` 00192
   /* works perfect thx to tsuji and gil davis */
   ch = ch.value.replace(/\u00C8/g,"E"); //not working
}

it does not seem to like the way I try running the second replace. Any hints or ideas?

Thanks again,
 
You have to read documents of scientific & technical nature careful to every detail. The reason is you lost the object reference along the way (comparing to what I posted.)
[tt]
var ch = document.form1["text"+i+"0"];
ch[red].value[/red] = ch.value.replace(/\u00C0/g,"A"); // A A` 00192
/* works perfect thx to tsuji and gil davis */
ch[red].value[/red] = ch.value.replace(/\u00C8/g,"E"); //not working
[/tt]
 
Also if the replacement candidate set is becoming larger, you can retrieve the value once and do all the replacements to the string and finally write it back.
[tt]
var ch = document.form1["text"+i+"0"];
var s=ch.value;
s = s.replace(/\u00C0/g,"A"); // A A` 00192
/* works perfect thx to tsuji and gil davis */
s = s.replace(/\u00C8/g,"E"); //not working
//etc etc ...
ch.value=s;
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top