PHP Drop Menu with onChange to populate hidden input prior to submit

I have the php code working to produce the drop menu and use the

onChange="flagmastcountryflag(this.value)"

to pass the value to javascript for process.

<?php
// Creates a pull-down list of flagmastcountries
  function get_flagmastcountry_list($name, $selected = '', $parameters) {
    $flagmastcountries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT_FLAGMASTCOUNTRY));
    $flagmastcountries = get_flagmastcountries();

    for ($i=0, $n=sizeof($flagmastcountries); $i<$n; $i++) {
      $flagmastcountries_array[] = array('id' => $flagmastcountries[$i]['countries_id'], 'text' => $flagmastcountries[$i]['countries_name']);
    }

    return draw_pull_down_menu($name, $flagmastcountries_array, $selected, $parameters);
  }

  function get_flagmastcountries($flagmastcountries_id = '', $with_iso_codes = true) {
    $flagmastcountries_array = array();

      $flagmastcountries = tep_db_query("select countries_id, countries_name from " . TABLE_FLAGMASTCOUNTRIES . " order by countries_name");
      while ($flagmastcountries_values = tep_db_fetch_array($flagmastcountries)) {
        $flagmastcountries_array[] = array('countries_id' => $flagmastcountries_values['countries_id'],
                                   'countries_name' => $flagmastcountries_values['countries_name']);

    }

    return $flagmastcountries_array;
    }
 	echo get_flagmastcountry_list('flagmastcountry','','onChange="flagmastcountryflag(this.value);"'); ?>

Which I then need to populate the hidden input at the point $flagmastcountryflag

            $tmp_html = '<input type="hidden" name ="id[' . TEXT_PREFIX . $products_options_name['products_options_id'] . ']" size="' . $products_options_name['products_options_length'] .'" maxlength="' . $products_options_name['products_options_length'] . '" value="' . $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] . $flagmastcountryflag .'">';

echo             '<td class="main">' . $tmp_html . '</td>';


Javascript needed

function flagmastcountryflag() {

this where the help is needed how code the function to pass the value of (this.value) and output.

I now have this for the javascript function

function flagmastcountryflag() {
  if(document.cart_quantity.flagmastcountry.options[0].value == true) {
    return false
  }
  else {
document.cart_quantity.idtxt_21.value=document.cart_quantity.flagmastcountry.options[document.cart_quantity.flagmastcountry.selectedIndex].text;
  }
  return true;
}

this works provided I change the php side to give the input field name idtxt_21, however I need the name to be id[txt_21] for later in the php process.

How do I get the javascript to work using id[txt_21] instead of idtxt_21