I'm pretty new with Drupal & JQuery. I post this question because I was not able to find a solution in the net.

I have a select form element to choose a country. This select displays de country names but keeps the country_code because this is the value to be stored in the DDBB once the form submitted. This select element is linked to ajax because there is a second select field which should show values depending on the selected country.

As soon as the complete address is introduced, JQuery should show a map with the location of the entered address. For that reason I need JQuery to access the country name before the form is submitted.

There is a function that returns the country name for a given country_code but I do not know how to run that function so that the result can be catched by JQuery. One solution would be keep the country_name instead of the country_code (in the select element) but then , into the submit function of the form, I would need a function to get the country code and I would like to avoid this.


$form['c_pais'] = array(
'#title' => t('Address - Country'),
'#type' => 'select',
'#options' => $country_list,
'#required' => TRUE, 
'#default_value' => $value_country,
'#ajax' => array(
    'event' => 'change',
    'callback' => 'call_region1_select',
    'wrapper' => 'dropdown_region1',

function get_country_list()
    $llista_paisos['0']='--- chosse a country ----';
    while($node = $result->fetchAssoc()) 
    return $llista_paisos;

1 Answer 1


Use like this to get form select list element in jQuery.

$("#elementId :selected").text() //the text content of the selected option(country name)
$("#elementId").val() //the value of the selected option(country code)
  • this solution did not work but helped me to find the correct one in my case. Some else asked similar question and solution given was $("#yourdropdownid option:selected").text(); and this ones wrorks for me. many thanks
    – David_A
    Commented Sep 25, 2015 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.