1,105,417 Community Members

Urgent, need help please

Member Avatar
dg12
Newbie Poster
3 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Philippe.Lahaie
Posting Whiz
376 posts since Oct 2007
Reputation Points: 42 [?]
Q&As Helped to Solve: 60 [?]
Skill Endorsements: 9 [?]
 
0
 

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?

Member Avatar
teedoff
Practically a Master Poster
605 posts since Jul 2010
Reputation Points: 3 [?]
Q&As Helped to Solve: 60 [?]
Skill Endorsements: 0 [?]
 
0
 

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
dg12
Newbie Poster
3 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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
dg12
Newbie Poster
3 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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??

Member Avatar
Philippe.Lahaie
Posting Whiz
376 posts since Oct 2007
Reputation Points: 42 [?]
Q&As Helped to Solve: 60 [?]
Skill Endorsements: 9 [?]
 
2
 
<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.

Member Avatar
almostbob
Nearly a Senior Poster
3,395 posts since Jan 2009
Reputation Points: 515 [?]
Q&As Helped to Solve: 425 [?]
Skill Endorsements: 14 [?]
 
1
 

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

Member Avatar
teedoff
Practically a Master Poster
605 posts since Jul 2010
Reputation Points: 3 [?]
Q&As Helped to Solve: 60 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article