Let's say I have a select box with values : 1, 2, 3, 4, 5, 6. Every value has it's own image, which I want to display as a description below the select field. Any Drupal / AJAX way to show this?

By the way this is NOT a custom form. This is a node creation and edit form.


As far as I know there are no ready made solutions for this, and you will need to write a custom module. The way to do this would be to implement hook_form_alter to modify the select element and add a #ajax property.

If you've never written a module with hook_form_alter then this article might be of help: very-introduction-drupals-hookformalter

And here are some relevant questions on Drupal answers:

| improve this answer | |
  • This is a good idea, but the select box is also a part of a conditional field. This will override the conditional field applied to the current field. – Akmal Fikri Mar 15 '13 at 14:23
  • 2
    After fiddling with hook_form_alter and #ajax property, apparently I had to use : 1. $form['field_for_ajax']['und']['#ajax'] - to trigger the ajax. 2. $form_state['values']['field_for_ajax']['und'][0]['value'] - to get the value of the select dropdown. Thanks Alice for the heads up! – Akmal Fikri Mar 18 '13 at 11:26
  • @AkmalFikri Can u post the solution plz? – Umair Apr 12 '17 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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