View Full Version : OnLoad Switch Content Script II

06-20-2007, 07:34 AM
1) Script Title: DD Switch Content Script II

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/switchcontent2.htm

3) Describe problem: I am using this script in a dynamic way with asp and a SQL query so the content appears on demand, for example, I have a list of movie titles and the showtimes are hidden, I would like to expand one specific movie depending on the user preference.

So I was reading in the threads and I found one that talk about this issue posted by spyr (07-03-2005, 03:08 PM) where he was trying to use this:

<body onLoad="expandcontent(this, 'sc1')">

but it did not work, and right after this he quoted: Never mind! Sorry to waste everyone's time but stupid me just found the answer.

I have played with this idea for ours but it seems that I am more stupid than spyr and cannot find the answer. Can someone please help I will appreciate it very much.

06-21-2007, 05:24 AM
Hmm that thread really isn't relevant anymore, as the script has long been rewritten. Can you describe in more detail what you're trying to accomplish?

06-21-2007, 02:43 PM
when the user goes to a detail movie page I show a list of movies that are playing in certain theater with the showtimes hidden and I want to expand the showtimes of the selected movie.

You can see an example here:


In this page you can see we are showing the movie shrek the third and I want to have the shrek the third showtimes expanded in the theater movie list on the right, since it is a dynamic list and you can change the theater the movie is not always in the same position, in this case the third position and I cannot use the defaultExpanded(2) because if you change the theater it will probably be in other position.

What I want to do is to open the content using the ID something like <body onLoad="expandcontent(this, 'movie3')"> but obviously this does not work.

I got the idea from one comment from spyr in the thread http://www.dynamicdrive.com/forums/showthread.php?t=48 where he had a similar problem and solve it but did not post the answer.

any ideas? or can you please point me to the new version of the script?

06-21-2007, 07:44 PM
No, you do have the new version of the script installed. I was referring to Spyr's post, which is based on the old version, and isn't applicable here even if a solution was mentioned.

If I understood your question correctly then, what you're basically trying to do is to be able to expand a content on demand based on the ID of the content. Add the below code to the end of switchicon.js:

//PUBLIC: Expands a content based on its ID entered

var header=document.getElementById(id+"-title")
var innercontent=document.getElementById(id)
if (this.collapsePrev && typeof this.prevHeader!="undefined" && this.prevHeader.id!=header.id) // If "Collapse Previous" is enabled and there's a previous open content
this.contractcontent(this.prevHeader) //Contract that content first
if (this.collapsePrev)
this.prevHeader=header //Set current expanded content as the next "Previous Content"

Then, in your HTML page, you can call userexpand() as you wish to expand a particular content on demand. For example:

var faq=new switchicon("icongroup1", "div") //Limit scanning of switch contents to just "div" elements
faq.setHeader('<img src="minus.gif" />', '<img src="plus.gif" />') //set icon HTML
faq.collapsePrevious(true) //Allow only 1 content open at any time
faq.setPersist(false) //No persistence enabled
//faq.defaultExpanded(0) //Set 1st content to be expanded by default


The code in red is new, and will expand the content "faq3" when the page fully loads.

06-23-2007, 01:29 AM
Thank you ddadmin this did the trick and you took a head ache away.

Thanks very much