here is the function
I am pretty sure that the problem is situated in the new Option() function
Expand|Select|Wrap|Line Numbers
- function showKens(){
- var kenList = document.form1.ken;
- var cityList = document.form1.city;
- var kenId = kenList.options[kenList.selectedIndex].value;
- var cityName = '';
- cityList.options.length = 0;
- i = 0;
- for (y in ken_array[kenId].city){
- cityName = ken_array[kenId].city[y];
- cityList.options[i] = new Option(cityName, y);
- i++;
- }
- }
Expand|Select|Wrap|Line Numbers
- cityList.options[i] = new Option('福岡', y);
- is displayed like 福岡
- instead of 福岡
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
- function new_location_edit($city01, &$dbread, $time, $default_language)
- {
- $userlang_ken="KenNameLan_".$_SESSION['userlanguage'];
- $defaultlang_ken="KenNameLan_".$default_language;
- $userlang_city="CityNameLan_".$_SESSION['userlanguage'];;
- $defaultlang_city="CityNameLan_".$default_language;;
- // echo "userlang: ".$userlang_ken;
- $TableName1 = 'ken';
- $TableName2 = 'city';
- //$Query is the query that select the list of prefecture ordered by name
- $QuerySelectKen = "SELECT $TableName1.*
- FROM $TableName1
- WHERE KenId <> 1
- order by $userlang_ken ASC, $defaultlang_ken ASC;";
- echo $QuerySelectKen . '<BR>';
- $Result1= $dbread->CacheGetAll($time,$QuerySelectKen);
- foreach($Result1 AS $Row1){
- if($Row1[$userlang_ken]==null){
- $kens[($Row1['KenId'])]['name'] = $Row1[$defaultlang_ken];
- }else{
- $kens[($Row1['KenId'])]['name'] = $Row1[$userlang_ken];
- }
- // $kens[($Row1['KenId'])]['name'] = $Row1['KenNameLan_1'];
- $QuerySelectCity = "SELECT $TableName2.*
- FROM $TableName2
- WHERE $TableName2.KenId = $Row1[KenId]
- OR $TableName2.KenId = '0'
- ORDER BY CityNameLan_1 ASC;";
- // echo $QuerySelectCity . '<BR>';
- $Result2 = $dbread->CacheGetAll($time,$QuerySelectCity);
- foreach($Result2 AS $Row2){
- if($Row2[$userlang_city]==null){
- //echo "<br />".$Row2['CityId']."null";
- $kens[($Row1['KenId'])]['city'][($Row2['CityId'])] = $Row2[$defaultlang_city];
- }else{
- // echo "<br />".$Row2['CityId'].": ".$Row2[$userlang_city]." ".$Row2[$defaultlang_city];
- $kens[($Row1['KenId'])]['city'][($Row2['CityId'])] = $Row2[$userlang_city];
- }
- }
- }
- //get the ken and city for this user
- if($city01!=null){
- $QuerySelectKenCity = "SELECT $TableName2.*, $TableName1.KenNameLan_1
- FROM $TableName2
- LEFT JOIN {$TableName1} ON {$TableName2}.KenId = {$TableName1}.KenId
- WHERE $TableName2.CityId = $city01;";
- }else{
- //echo "city = null";
- $QuerySelectKenCity = "SELECT $TableName2.*, $TableName1.*
- FROM $TableName2
- LEFT JOIN {$TableName1} ON {$TableName2}.KenId = {$TableName1}.KenId
- WHERE $TableName2.CityId = 1;";
- }
- // echo $QuerySelectKenCity;
- $Row3 = $dbread->CacheGetRow($time,$QuerySelectKenCity);
- //echo "KEN: ".$Row3['KenNameLan_1'].$Row3['KenId'];
- //echo "CITY: ".$Row3['CityNameLan_1'].$Row3['CityId'];
- print <<<LLL
- <script language="Javascript" type="text/javascript">
- <!--
- function showKens(){
- var kenList = document.form1.ken;
- var cityList = document.form1.city;
- var kenId = kenList.options[kenList.selectedIndex].value;
- var cityName = '';
- cityList.options.length = 0;
- i = 0;
- for (y in ken_array[kenId].city){
- cityName = ken_array[kenId].city[y];
- cityList.options[i] = new Option(cityName, y);
- i++;
- }
- }
- var ken_array = new Array();
- LLL;
- foreach ($kens as $kenId=>$kenDetails){
- $kenName = $kenDetails['name'];
- print <<<LLL
- ken_array[$kenId] = new Array();
- ken_array[$kenId].name = '$kenName';
- ken_array[$kenId].city = new Array();
- LLL;
- foreach ($kenDetails['city'] as $cityId=>$city){
- print <<<LLL
- ken_array[$kenId].city[$cityId] = '$city';
- LLL;
- }
- }
- print <<<LLL
- document.write('<select name="ken" onchange="showKens()">');
- LLL;
- if($Row3[$userlang_ken]==null){
- print <<<LLL
- document.write('<option value="$Row3[KenId]">$Row3[$defaultlang_ken]</option>');
- LLL;
- }else{
- print <<<LLL
- document.write('<option value="$Row3[KenId]">$Row3[$userlang_ken]</option>');
- LLL;
- }
- print <<<LLL
- for (var i in ken_array){
- document.write('<option value="'+i+'">'+ken_array[i].name+'</option>');
- }
- document.write('</select>');
- document.write('<input name="kenname" type="hidden" value="$Row3[KenNameLan_1]" />');
- LLL;
- if($Row3[$userlang_city]==null){
- print <<<LLL
- document.write('<select name="city"><option value="$Row3[CityId]">$Row3[$defaultlang_city]</option></select>');
- LLL;
- }else{
- print <<<LLL
- document.write('<select name="city"><option value="$Row3[CityId]">$Row3[$userlang_city]</option></select>');
- LLL;
- }
- print <<<LLL
- document.write('<input type="hidden" name="cityname" value="$Row3[CityNameLan_1]" />');
- -->
- </script>
- LLL;
- }
- Thank you for looking
- anatak