displaying Japanese text with new Option does not work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anatak
    New Member
    • Jan 2007
    • 1

    displaying Japanese text with new Option does not work

    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
    Code:
    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++;
    		}
    	}
    if I try to hard code a japanese city name in the new Option() function
    Code:
    cityList.options[i] = new Option('福岡', y);
    is displayed like 福岡 
    instead of 福岡
    cityList.option s[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)
    Code:
    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
    Last edited by anatak; Jan 21 '07, 01:11 PM. Reason: japanese was displayed correctly. I will put the comment in the code
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    &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.option s[i] = new Option('福岡', y);

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

    in this i don't even see an & or &amp; in your new option?

    Comment

    Working...