2016-11-18 47 views
0

我有selectbox在選擇相關城市的基礎上顯示區域。通過onchange事件向javascript傳遞兩個或更多值

foreach ($pr_districts as $list) { 

    $valueid = $this->escapeHtml ($list->id); 
    $value = $this->escapeHtml ($list->d_name); 
    $districts_option [] = array('value' => $valueid, 'label' => $value); 
}  
    $district_form->get('districts')->setAttributes(array('options' => $districts_option, 'onChange'=>"getCities(this.value)")); 

這裏id(存儲在value)選定區被傳遞到getCities()

我想通過省編號p_idgetCities()然後在那裏訪問它。我不知道該怎麼做。

請指導我的朋友。提前致謝。

回答

2

,你可以通過它像:

... 
$district_form->get('districts') 
    ->setAttributes(
     array(
      'options' => $districts_option, 
      'onChange'=>"getCities(this.value, '$yourIDHere')" 
     ) 
    ); 
+0

注意,'setAttributes()'用鑰匙: '選項',將調用'setValueOptions()',它會更新'InArray'驗證。這將被棄用一段時間,請參閱:[Zend \ Form \ Element \ Select :: setAttributes()](https://github.com/zendframework/zend-form/blob/master/src/Element/Select.php# L162)。所以最好分別調用' - > setValueOptions()'。 – Kwido

相關問題