1

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?

2 Answers 2

1

Try:

function checkbox1($form, &form_state) {

and:

function checkbox_ajax($form, $form_state) {
Sign up to request clarification or add additional context in comments.

Comments

1
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.

Comments

Your Answer

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