このように、 selection.phpの 2 つの配列を smartyに割り当てました。
$country = array(
'1' => 'Japan',
'2' => 'Australia',
'3' => 'India'
);
$city = array(
'1' => array(
'10' => 'Tokyo',
'11' => 'Osaka'
),
'2' => array(
'20' => 'Sydney',
'21' => 'Melbourne'
),
'3' => array(
'30' => 'Mumbai',
'31' => 'Delhi'
)
);
$smarty->assign('country_select',$country);
$smarty->assign('city_select',$city);
$smarty->display('selection.tpl');
selection.tplのコードは次のようになります。
<div>{html_options id='country_select' options=$country_select}</div>
<div>{html_options id='city_select' options=$city_select}</div>
ここでやりたいことは、country_select ドロップダウンで国を選択すると、city_select ドロップダウンの項目が国の選択に従って変更されるという jQuery 関数を作成することです。つまり、country_select ドロップダウンで「Australia」を選択すると、city-select ドロップダウンで「Sydney」と「Melbourne」以外のオプションが削除されます。
jQueryコードがどうなるか教えてください。$city_select 配列を jQuery に渡すことができませんでした。