Hello, first of all, I have a javascript, and I want to insert it in Drupal. The javascript shows/hide a

tag when a link is clicked . ( onclick atribute).

OK, in my module, I add the Javascript with drupal_add_js, and the link is something like this: "<a href="#" onclick="show('the_class_atribute_of_the_div')">Show</a>"...
But nothing happens when I click on it.

I tried also this : "<a href="javascript:show('the_class_atribute_of_the_div')">Show</a>"

with the same result.
I have read the handbook, but I can guess what it's wrong.

When I click in the link, the firefox javascript console, says: "show is not defined".

Comments

nevets’s picture

At some point you need to include the javascript that defines the function show(). Are you doing that?

keo01’s picture

yes, I do with drupal_add_js($path.'/show.js'), and in the html source code of my web, I can see it in the head section... <script type="text/javascript" src="/modules/mymodule/show.js"></script>.

Jacob’s picture

The reason that nothing happens is that Drupal parses out "suspicious" elements.
Your code
<a href="#" onclick="show('the_class_atribute_of_the_div')">Show</a>
probably produces
<a href="#">Show</a> - check out the page source code
The default Drupal settings for the "Input format" is "Filtered HTML" and it does what it's intended for - strip out the suspicious code. Change "Input format" to "Full HTML" and you are done.

Unfortunately, there is no way to define Input format per role or per user - see topics http://drupal.org/node/11218 and http://drupal.org/node/34205.
This would be really helpfull.

Jacob.

pps-1’s picture

I can see your show.js?