469,964 Members | 1,483 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

displaying Japanese text with new Option does not work

1
Hello I have function that generates a list op options for a select dropdown box

here is the function
I am pretty sure that the problem is situated in the new Option() function
Expand|Select|Wrap|Line Numbers
  1. function showKens(){
  2.         var kenList = document.form1.ken;
  3.         var cityList = document.form1.city;
  4.         var kenId = kenList.options[kenList.selectedIndex].value;
  5.         var cityName = '';
  6.         cityList.options.length = 0;
  7.         i = 0;
  8.         for (y in ken_array[kenId].city){
  9.             cityName = ken_array[kenId].city[y];
  10.             cityList.options[i] = new Option(cityName, y);
  11.             i++;
  12.         }
  13.     }
  14.  
if I try to hard code a japanese city name in the new Option() function
Expand|Select|Wrap|Line Numbers
  1. cityList.options[i] = new Option('福岡', y);
  2. is displayed like 福岡 
  3. instead of 福岡
  4.  
cityList.options[i] = new Option('福岡', y);

the name is not displayed correctly because the & is changed into &

does anyone know how to make sure Javascript does not change the value of the & into &

Here is the complete function (mix of php and javascript)
Expand|Select|Wrap|Line Numbers
  1. function new_location_edit($city01, &$dbread, $time, $default_language)
  2. {
  3.     $userlang_ken="KenNameLan_".$_SESSION['userlanguage'];
  4.     $defaultlang_ken="KenNameLan_".$default_language;
  5.     $userlang_city="CityNameLan_".$_SESSION['userlanguage'];;
  6.     $defaultlang_city="CityNameLan_".$default_language;;
  7. //    echo "userlang: ".$userlang_ken;
  8.     $TableName1 = 'ken';
  9.     $TableName2 = 'city';
  10.     //$Query is the query that select the list of prefecture ordered by name
  11.     $QuerySelectKen = "SELECT $TableName1.* 
  12.                         FROM $TableName1 
  13.                         WHERE KenId <> 1
  14.                         order by $userlang_ken ASC, $defaultlang_ken ASC;";
  15.     echo $QuerySelectKen . '<BR>';
  16.     $Result1= $dbread->CacheGetAll($time,$QuerySelectKen);
  17.     foreach($Result1 AS $Row1){
  18.         if($Row1[$userlang_ken]==null){
  19.             $kens[($Row1['KenId'])]['name'] = $Row1[$defaultlang_ken];
  20.         }else{
  21.             $kens[($Row1['KenId'])]['name'] = $Row1[$userlang_ken];
  22.         }
  23.  
  24. //        $kens[($Row1['KenId'])]['name'] = $Row1['KenNameLan_1'];
  25.         $QuerySelectCity = "SELECT $TableName2.* 
  26.                             FROM $TableName2 
  27.                             WHERE $TableName2.KenId = $Row1[KenId]
  28.                             OR $TableName2.KenId = '0'
  29.                             ORDER BY CityNameLan_1 ASC;";
  30. //        echo $QuerySelectCity . '<BR>';
  31.         $Result2 = $dbread->CacheGetAll($time,$QuerySelectCity);
  32.         foreach($Result2 AS $Row2){
  33.             if($Row2[$userlang_city]==null){
  34.                 //echo "<br />".$Row2['CityId']."null";
  35.                 $kens[($Row1['KenId'])]['city'][($Row2['CityId'])] = $Row2[$defaultlang_city];
  36.             }else{
  37. //                echo  "<br />".$Row2['CityId'].": ".$Row2[$userlang_city]." ".$Row2[$defaultlang_city];
  38.                 $kens[($Row1['KenId'])]['city'][($Row2['CityId'])] = $Row2[$userlang_city];
  39.             }
  40.         }
  41.     }
  42.     //get the ken and city for this user
  43.     if($city01!=null){    
  44.         $QuerySelectKenCity = "SELECT $TableName2.*, $TableName1.KenNameLan_1
  45.                                 FROM $TableName2 
  46.                                 LEFT JOIN {$TableName1} ON {$TableName2}.KenId = {$TableName1}.KenId 
  47.                                 WHERE $TableName2.CityId = $city01;";
  48.     }else{
  49.         //echo "city = null";
  50.         $QuerySelectKenCity = "SELECT $TableName2.*, $TableName1.*
  51.                                 FROM $TableName2 
  52.                                 LEFT JOIN {$TableName1} ON {$TableName2}.KenId = {$TableName1}.KenId 
  53.                                 WHERE $TableName2.CityId = 1;";
  54.  
  55.     }
  56. //    echo $QuerySelectKenCity;
  57.     $Row3 = $dbread->CacheGetRow($time,$QuerySelectKenCity);
  58.     //echo "KEN: ".$Row3['KenNameLan_1'].$Row3['KenId'];
  59.     //echo "CITY: ".$Row3['CityNameLan_1'].$Row3['CityId'];
  60.  
  61.     print <<<LLL
  62.     <script language="Javascript" type="text/javascript">
  63.     <!--
  64.     function showKens(){
  65.         var kenList = document.form1.ken;
  66.         var cityList = document.form1.city;
  67.         var kenId = kenList.options[kenList.selectedIndex].value;
  68.         var cityName = '';
  69.  
  70.         cityList.options.length = 0;
  71.  
  72.         i = 0;
  73.         for (y in ken_array[kenId].city){
  74.             cityName = ken_array[kenId].city[y];
  75.             cityList.options[i] = new Option(cityName, y);
  76.             i++;
  77.         }
  78.     }
  79.     var ken_array = new Array();
  80. LLL;
  81.     foreach ($kens as $kenId=>$kenDetails){
  82.         $kenName = $kenDetails['name'];
  83.         print <<<LLL
  84.  
  85.         ken_array[$kenId] = new Array();
  86.         ken_array[$kenId].name = '$kenName';
  87.         ken_array[$kenId].city = new Array();
  88. LLL;
  89.         foreach ($kenDetails['city'] as $cityId=>$city){
  90.             print <<<LLL
  91.  
  92.             ken_array[$kenId].city[$cityId] = '$city';
  93. LLL;
  94.         }
  95.     }
  96.     print <<<LLL
  97.  
  98.     document.write('<select name="ken" onchange="showKens()">');
  99. LLL;
  100.     if($Row3[$userlang_ken]==null){
  101.         print <<<LLL
  102.         document.write('<option value="$Row3[KenId]">$Row3[$defaultlang_ken]</option>');
  103. LLL;
  104.     }else{
  105.         print <<<LLL
  106.         document.write('<option value="$Row3[KenId]">$Row3[$userlang_ken]</option>');
  107. LLL;
  108.     }
  109.     print <<<LLL
  110.     for (var i in ken_array){
  111.         document.write('<option value="'+i+'">'+ken_array[i].name+'</option>');
  112.     }
  113.     document.write('</select>');
  114.     document.write('<input name="kenname" type="hidden" value="$Row3[KenNameLan_1]" />');
  115. LLL;
  116.     if($Row3[$userlang_city]==null){
  117.         print <<<LLL
  118.         document.write('<select name="city"><option value="$Row3[CityId]">$Row3[$defaultlang_city]</option></select>');
  119. LLL;
  120.     }else{
  121.         print <<<LLL
  122.         document.write('<select name="city"><option value="$Row3[CityId]">$Row3[$userlang_city]</option></select>');
  123. LLL;
  124.     }
  125.     print <<<LLL
  126.     document.write('<input type="hidden" name="cityname" value="$Row3[CityNameLan_1]" />');
  127.     -->
  128.     </script>
  129. LLL;
  130. }
  131.  
  132. Thank you for looking
  133.  
  134. anatak
  135.  
Jan 21 '07 #1
1 1432
iam_clint
1,208 Expert 1GB
&amp; is the same as &

the &amp; is the html equivilent and is used for query strings usually such as GET or POST in a form.


cityList.options[i] = new Option('福岡', y);

is displayed like &amp;#31119;&amp;#23713;
instead of 福岡

in this i don't even see an & or &amp; in your new option?
Jan 22 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Sriv Chakravarthy | last post: by
3 posts views Thread by Benoit Martin | last post: by
7 posts views Thread by Daniel | last post: by
4 posts views Thread by Thorben | last post: by
11 posts views Thread by pardesiya | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.