Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By keo01 on
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
How are you including the javascript
At some point you need to include the javascript that defines the function show(). Are you doing that?
yes, I do with
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>
.The reason is Input format=Filtered HTML
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 codeThe 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.
I can see your show.js?
I can see your show.js?