I have an html select element generated in PHP from an array as follows
$countries = array( array('iso' => 'AF', 'name' => 'Afghanistan', 'key' => 'Red'), array('iso' => 'AX', 'name' => 'Γ
land Islands','key' => 'Yellow'), array('iso' => 'AL', 'name' => 'Albania', 'key' => 'Blue') ); $select = '<select id="country_select" onchange="countryfind()">'; foreach($countries as $country) { $select .= '<option value="'.$country['key'].'">'.$country['name'].'</option>'; } $select = '</select>'; return $select;
The javascript function is used in the selection field to display the country key of the selected country:
function countryfind(){ jQuery('#countrykey').text( jQuery('#country_select option:selected').val() )};
I want to use this key to interact with another PHP array that contains country information and displays that country in div # countrykey instead of the selected value:
$si_federations = array( 'Red' => array('name'=>'A Red Country', 'url'=>'http://www.redcountry.com'), 'Blue' => array('name'=>'A Blue Country', 'url'=>'http://www.soroptimisteurope.org'), );
Is this something that can be easily achieved, or is my approach completely wrong?
source share