Drupal 7 Form AJAX button to return javascript script I am trying to create a form that allows a user to type in an address and click submit. In return the button makes an AJAX callback that builds the javascript link for a user to copy and paste into their site. Once a user inserts the javascript into their site it will display a map from my site. The problem I am having is when the user creates their custom map using my form I want to return a sample map of what it should look like. I need this javascript to be printed to the browser.

&lt;script type="text/javascript" src="http://widget.pickerspal.com/search/get?lat=41.6005448&amp;lng=-93.6091064&amp;height=500"&gt;&lt;/script&gt;


But when it is returned nothing is displayed. Here is my form &amp; callback function.

function d3vo_widget_builder_form($form, &amp;$form_state) {
    $form['city'] = array(
      '#title' =&gt;   t('City'),
      '#type' =&gt;    'textfield',
      '#required' =&gt; TRUE,
      '#description' =&gt; t('Find your city'),
    );

    $form['height'] = array(
      '#title' =&gt;   t('Widget Height'),
      '#type' =&gt;    'textfield',
      '#size' =&gt; 5,
      '#description' =&gt; t('Set the widget height'),
      '#element_validate' =&gt; array('_validate_field_is_numeric'),
    );

    $form['map-area'] = array(
      '#type' =&gt; 'markup',
      '#prefix' =&gt; '&lt;div id="mapsample-div"&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
      );

    $form['submit'] = array(
      '#type' =&gt;    'button',
      '#value' =&gt;   'Get Widget',
      '#ajax' =&gt; array(
        'callback' =&gt; 'd3vo_widget_map_ajax_callback',
        'wrapper' =&gt; 'mapsample-div',
        'method' =&gt; 'html',
        'effect' =&gt; 'fade',
        //'progress' =&gt; array('type' =&gt; 'none'),
    ),
    );

    return $form;   

function d3vo_widget_map_ajax_callback($form, $form_state){
       $point = geocoder('google',$form_state['values']['city']);
       $lng = $point-&gt;coords[0];
       $lat = $point-&gt;coords[1];
       if($form_state['values']['height'] == NULL){
           $height = 500;
       } else {
       $height = $form_state['values']['height'];
       }
       $widgetScript = '&lt;script type="text/javascript" src="http://widget.pickerspal.com/search/get?lat='. $lat .'&amp;lng='. $lng . '&amp;height='.$height.'"&gt;&lt;/script&gt;';

        $form['script'] = array(
         '#value' =&gt; $widgetScript,
         '#type' =&gt; 'textfield',
         '#attributes' =&gt; array('readonly' =&gt; 'readonly'),
         );

        $form['map'] = array(
          '#type' =&gt; 'markup',
          '#markup' =&gt; $widgetScript,
        );

        return array($form['script'], $form['map']);
    }


Im not very familiar with using Javascript in Drupal. I have searched and tried many different ways but I can not get the map area to show. Any help would be greatly appreciated.
The AJAX callback is only used to tell Drupal's AJAX engine what part of form to update. All actual work of building the form elements is supposed to happen in form's hook, in code wrapped in a control statement like the following.

if (!empty($form_state['values'])) {
  // ...
}