PDA

View Full Version : Pass parameters through URL



Schmoopy
12-01-2008, 01:22 AM
Ok, so I recently redid my site, so there are multiple pages on one.

You can see an example of this here:

http://bombthehills.com/newstuff/guides.html

Just press the tabs and you'll see what I mean.

But I do have other pages that link back to, for example, the "board maintenance" tab, but it's still on the guides.html page.

And the content for it is contained in a div, so I want this sort of thing, but translated into a URL if it's possible:

document.getElementById('maintenance').style.display='block';

Is this possible? maybe not even this, but something that has the same effect. I hope it can be done, since I really want to have content put in tabs like this, where the page doesn't change.

Thanks very much for any help given,

Jack.

codeexploiter
12-01-2008, 04:46 AM
In your approach I think two JS functions are using for hiding/showing the tabs; one for hiding all the tab content div element and another one for showing the needed div element.

I think you can use the following function and associate this function and pass the element id which clicked. Maintain an element ID array inside the function through which you can display and hide the div element. The logic is to display the div element whose ID passed into the function rest of the elements will be hidden.


function displayTheClickedTab(clickedId){
var tabContentId = ['intro','maintenance','ridetips','tricktips']; //Enter the element ids which is the container of the tabs like the mentioned ones.
if(document.getElementById(clickedId)){
document.getElementById(clickedId).style.display = 'block';
}

for(var i = 0; i < tabContentId.length; i++){
if(tabContentId[i] !== clickedId){
document.getElementById(tabContentId[i]).style.display = 'none';
}
}
}

Hope this helps

Schmoopy
12-01-2008, 08:56 AM
Yea, thanks very much for that - helps condense the code into one function which will definitely save time and space, I knew it could be done but I'm not really experienced enough at JavaScript to know how to do it.

Anyway, maybe this makes it easier to pass that function through a URL?

jscheuer1
12-01-2008, 08:56 AM
http://www.dynamicdrive.com/dynamicindex17/tabcontent.htm


(v 2.2) A link from another page linking to the target page can select a tab on the later when loaded, via the URL parameter string ((ie: http://mysite.com/tabcontent.htm?tabinterfaceid=0).

Schmoopy
12-01-2008, 09:04 AM
Thanks for that, but I'm still not sure how I would do it on my page, the code on that page seems very complicated, any way I could condense it down without having to copy a load off of that script?

Would it be something like: www.bombthehills.com/guides.html?displayTab=1

?

jscheuer1
12-01-2008, 09:12 AM
You could write your own code to snag the query string from the URL and to then do something with it. But that seems about as complicated, if not more so, as using the script I suggest. With the Dynamic Drive script, all you have to do is follow the instructions.

Schmoopy
12-01-2008, 12:53 PM
Yea, thanks for that, I've implemented the new tab code, but still having problems - follow on thread here: http://www.dynamicdrive.com/forums/showthread.php?t=39276

Edit: How has this got over 3000 views in a day? :S, bot?