473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

One javascript used multiple times on same page Question

Tried searching for the right article and saw some similar questions that if I knew more would probably be helpful, but I couldn't get the coding exactly right for my specific situation. So, thanks in advance for helping me out.

Question - I am implementing a drop down javascript box for photos and would like to duplicate the same script for multiple photos. Looking at the code, I see the interference (ie, the second picture still references the function code from the first script) however, renaming the function and calling it again in the script just switches the first picture to the second picture function.

Website, www.thelampoonjournal.com/news/sports.html - you can see the photo issue coming from below in the "Coming Up" section. How do I alter this code to reuse over and over - what is the call change needed:

[html]
<style type="text/css"> /* the box on top of the box we wish to show - this one hide the second one we set the height as 0.1 to avoid an IE bug when the height is 0.*/
#coverlogin
{
width: 215px;
height: 0.1em;
overflow:hidden;
visibility: hidden;
}

#loginbox
{
width: 215px;
height: auto;
border: 0px solid red;
background-color: #535353;
color:white;
}

</style>
<script type="text/javascript">

var hh=0;var inter;

//we show the box by setting the visibility of the element and incrementing
the height smoothlyfunction

ShowBox()
{
//Depending on the amount of text, set the maximum height here
in pixels
if(hh==80)
{
clearInterval(inter);
return;
}
obj = document.getElementById("coverlogin");
obj.style.visibility = 'visible'; hh+=2;
obj.style.height = hh + 'px';}

//same way as above but reversedfunction HideBox()

{
obj = document.getElementById("coverlogin"); if(hh==2) {
obj.style.visibility = 'hidden';
obj.style.height = '0.1em';
clearInterval(inter); return; } hh-=2;
obj.style.height = hh + 'px';
}

</script>
<!-- set an interval for the increment of the height by clicking onto this link -->
<a href="#" onclick="inter=setInterval('ShowBox()',3);return false;">
Click here to show the box</a>
<div id="coverlogin">
<div id="loginbox"><span class="style110">Texas Tech students leave ‘Physics 201’ class 5 minutes early after accidentally misreading the clock. </span>
<a href="#" onClick="inter=setInterval('HideBox()',3);return false;">Close It</a>
</div>
</div>
[/html]
Nov 4 '08 #1
3 1846
acoder
16,027 Expert Mod 8TB
Change ShowBox and HideBox to accept parameters and pass the ID of the div to be shown. Then within the function, change the line which gets the element by its id to use the passed string instead.
Nov 5 '08 #2
Change ShowBox and HideBox to accept parameters and pass the ID of the div to be shown. Then within the function, change the line which gets the element by its id to use the passed string instead.
Got it to work, thanks. All I really did is change all the commands, even in the css part to coverbox2 / loginbox2 / Showbox2 () / Hidebox2 () for everywhere they were in the script and it works now - www.thelampoonjournal.com/sports - and did it "3" for each section in the third and it works separately now.

Thanks again for your response, the help is really appreciated. My html is pretty sloppy, so my next job is to clean it up a bit.
Nov 5 '08 #3
acoder
16,027 Expert Mod 8TB
It seems a bit redundant to have three sets of functions when you could have just one. While you're cleaning up the HTML, you should try to improve the JavaScript code too by reusing the two functions for all photos.
Nov 6 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.