Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal 7 checkboxes array replace with ajax callback
    primarykey
    data
    text
    <p>I have the state field as dropdown. While onchange the state the cities should be viewed in check boxes. Below is my code</p> <pre><code>$form['rate_the_service']['state'] = array( '#type' =&gt; 'select', '#prefix'=&gt;'&lt;div id="dropdown-third-replace"&gt;', '#suffix'=&gt;'&lt;/div&gt;', '#options'=&gt;array( '0' =&gt; t('state1'), '1' =&gt; t('state2'), '2' =&gt; t('state3') ), '#attributes' =&gt; array( 'selected' =&gt; array('selected') ), '#validated' =&gt; TRUE, '#ajax' =&gt; array( 'callback' =&gt; 'ajax_example_dependent_dcheck_state_callback', 'wrapper' =&gt; 'checkboxes-four-replace', ), '#suffix'=&gt;'&lt;/div&gt;', ); </code></pre> <p>So while on change the state the cities will be displayed in check boxes using the function callback "ajax_example_dependent_dcheck_state_callback"</p> <p>Below is the default city code:</p> <pre><code>$cityarray = array( '1' =&gt; 'chk1' ); $form['rate_the_service']['city'] = array( '#prefix'=&gt;'&lt;div id="checkboxes-four-replace"&gt;', '#type' =&gt; 'checkboxes', '#options' =&gt; $cityarray, '#default_value' =&gt; isset($values['city']) ? $values['city'] : NULL, '#suffix'=&gt;'&lt;/div&gt;&lt;/div&gt;', ); </code></pre> <p>/////////// On changege ajax_example_dependent_dcheck_state_callback function call</p> <pre><code>function ajax_example_dependent_dcheck_state_callback($form, $form_state) { $state = $form_state['values']['state']; $city_array = array( '0' =&gt; 'city1', '2' =&gt; 'city2', '3' =&gt; 'city3' ); $options[$state] = $city_array; $form['rate_the_service']['city']['#options'] = $city_array; return $form['rate_the_service']['city']; } </code></pre> <p>While onchange the state the 'checkboxes-four-replace' will be replaced with the city1,2,3 checkboxes</p> <p>The onchange function is not working. If i change the type as ''#type' => 'select' ' instead of " '#type' => 'checkboxes' " its working fine. But i need tis as checkboxes. What i am wrong here. Please help me. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload