简体   繁体   中英

Drupal AJAX checkbox

When click on checkbox I want to call function checkbox_ajax, I tried but it does not work

function checkbox1($form_state) {
    $form['checkbox'] = array(
                '#type' => 'checkbox',
                '#prefix' => "<div class='rowH'>",
                '#suffix' => "</div>",
                '#ajax' => array(
                  'callback' => 'checkbox_ajax',
                'wrapper' => 'checkbox_ajax-wrapper'
                ),
                  ); 
    return $form;
}

I need to change prefix class

function checkbox_ajax($form, &$form_state) {

  $form['checkbox']['#prefix'] = "<div class='rowHB'>";

  return $form['checkbox'];  

}

if someone can help?

function checkbox1($form_state) {
    $form['checkbox'] = array(
                '#type' => 'checkbox',
                '#prefix' => (isset($form_state['values']['checkbox']) && $form_state['values']['checkbox'] ) ? "<div class='rowHB'>" : "<div class='rowH'>", //CHANGE HERE
                '#suffix' => "</div>",
                '#ajax' => array(
                  'callback' => 'checkbox_ajax',
                'wrapper' => 'checkbox_ajax-wrapper'
                ),
                  ); 
    return $form;
}

if $form['checkbox'] is checked than $form_state['values']['checkbox'] will equal to 1 thus ($form_state['values']['checkbox']) will equal to true.

I think this should work, but didn't test yet.

Try:

function checkbox1($form, &form_state) {

and:

function checkbox_ajax($form, $form_state) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM