This is a follow on to my previous question. I didn't want to make ajax calls for this and instead loaded all the term field text with views_get_view_result(). Then I looped over the results and created divs within the node add/edit form.

I know have for every term option in the select box a hidden div:

<div id=help123 style="visibility:hidden;">help text for termid 123</div>

I added a

scripts[] = custom.js

to my module.info file with:

    var option = document.getElementById("edit-field-disc-topic-und").value;     
    document.getElementById(option).style.visibility ="visible";

Should I post this on Stackoverflow instead?

  • Why didn't you want to make AJAX calls? This method (although it works, don't get me wrong - I'm not saying it's the wrong way to do it) seems much more inefficient as you are loading a lot of data that may not be seen by the user. – Chapabu Apr 18 '12 at 8:45
  • @Chapabu i understand the OP - the drupal bootstrap may be way more expensive than a few divs more ... – mojzis Apr 18 '12 at 9:33
  • yes, that was my reasoning. I was worried about delays – uwe Apr 18 '12 at 16:00
  • @MotoTribe i improved the answer, i am not sure i understand your question though :) (where is the problem, just that it doesnt show ?) – mojzis Apr 18 '12 at 16:50

you ommited the drupal.behavior, that s probably why it doesnt do anything. And i would suggest working with classes instead changing style. In your css you create a style with visibility:hidden, apply it to each element and then remove it on click. (and add it again once you clicked on something else ...)

document.getElementById doesnt make much sense there ... you can write it better like this :

Drupal.behaviors.taxdescGetDesc = {
  attach: function (context) {
    option = $(event.currentTarget).val();
|improve this answer|||||

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.