Member Avatar for dg12

Please help! I have this code copied from another of my blogs.

In the first blog it works completely fine, on the new blog it does nothing. Help please:

<script type="text/javascript"><br />function show_hide(adad) { <br />if(document.getElementById(adad)) { <br />if(document.getElementById(adad).style.display == 'none') { <br />document.getElementById(adad).style.display = 'inline'; } else { <br />document.getElementById(adad).style.display = 'none'; } } }</script>

<a href="javascript:show_hide('info');">
<img border="" width="180" alt="Informações Adicionais" src="http://i921.photobucket.com/albums/ad51/clube_skdp/Campeonato%202012/CabealhoCampeonatoTitulo.png" height="45" />
</a>


<div id="Informações" style="display: none;">

               
<a href="https://docs.google.com/viewer?a=v&amp;pid=explorer&amp;chrome=true&amp;srcid=0B6O8L2QzuOPbYWM2MzViMGQtNzI5OS00NDUyLTk1NWMtMmU1NGRjZWNmNGJh&amp;hl=en_US"><span style="font-family:comic sans;color:#c0c0c0;"><strong>lololol</strong></span></a>




               
<a href="https://docs.google.com/viewer?a=v&amp;pid=explorer&amp;chrome=true&amp;srcid=0B6O8L2QzuOPbOWQ2MzA5MjUtZDk3NC00OTRhLWFhNDctNWEwMzMyN2MzNzIy&amp;hl=en_US"><span style="font-family:comic sans;color:#c0c0c0;"><strong>Informações Época 2010-2011</strong></span></a>


</div>

thanks in advance

im guessing its because the javascript is hardcoded to work with a certain id, and the div you are trying to hide is not using that id

also im not sure its good practice to have <br>s in your script block but im guessing that was added for the post and its not in your actualy code?

So the function, which btw is javascript and probably should have posted in the javascript forum, is calling an element with an id of "adad"

document.getElementById(adad)

I dont see that element in your html code anywhere.

Member Avatar for dg12

im guessing its because the javascript is hardcoded to work with a certain id, and the div you are trying to hide is not using that id

also im not sure its good practice to have <br>s in your script block but im guessing that was added for the post and its not in your actualy code?

Yes, the <br>s are just for the blog, and they work. I altered the id (previously: the_layer) to 'adad', but the rest is completely the same as the previous blog has. And it worked. Nt even with the previous ID it works, I click on it and it does nothing...

Member Avatar for dg12

So the function, which btw is javascript and probably should have posted in the javascript forum, is calling an element with an id of "adad"

document.getElementById(adad)

I dont see that element in your html code anywhere.

the previous ID was 'the_layer' i think, but that wasn't the problem, because in one blog it works perfectly, and than when i do a copy paste to another blog, the show/hide function does not work when i click on the button.

So i think that isn't the problem. But I have no idea what's wrong. Maybe something in the new blog??

<a href="javascript:show_hide('info');">
<img ... />
</a>
<div id="Informações" style="display: none;">

the image link calls the javascript function with "info" as argument, (in the javascript function adad is the argument received)

but the hidden div's id is "Informações" not "info"

thats what i meant with my first post. sorry if it wasn't clear enough.

commented: + +13

teedoff: adad is a javascript local variable defined in the script at the top of the op function show_hide(adad) it only exists within the scope of the function, you can code many functions with the same local variable name without error, makes it simpler to reuse functions

DG12

<a href="javascript:show_hide('info');"> </a>  
<div id="Informações" style="display: none;">

the parameter in the function call and the id of the hidden div, really need to match
probably easier to change the hidden div id = "info"

edit; apologies Phillipe, already answered

teedoff: adad is a javascript local variable defined in the script at the top of the op function show_hide(adad) it only exists within the scope of the function, you can code many functions with the same local variable name without error, makes it simpler to reuse functions

Ahh lol thanks Bob, my lack of js skills shows! Which is why I guess I suggested the OP might have more luck in the js forum. Seems you solved it though...well I guess you have, since the OP hasn't responded.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.