homepage Welcome to WebmasterWorld Guest from 54.167.179.48
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Spry tab panel - select panel via URL parameter?
rich_b

10+ Year Member



 
Msg#: 3412646 posted 1:10 pm on Aug 3, 2007 (gmt 0)

I have a page that contains a set of tabbed panels using Spry JS code. I can use the following code to set the default panel when the page loads which works fine:

<script type="text/javascript">
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", { defaultTab: 1 });
</script>

What I'd like to do now is change the code so defaultTab gets its value from a query string parameter when the page is called.

i.e. [mydomain...]

I've tried a few things but can't get it to work. Is it possible?

 

Trace

5+ Year Member



 
Msg#: 3412646 posted 1:44 pm on Aug 3, 2007 (gmt 0)

Without actually being able to test it, I think something like this could work;
<script type="text/javascript">
function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = strHref.substr(strHref.indexOf("?"));
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return strReturn;
}

var theTab = getURLParam('tab');
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", { defaultTab: theTab });
</script>


rich_b

10+ Year Member



 
Msg#: 3412646 posted 2:15 pm on Aug 3, 2007 (gmt 0)

Hi Trace, thanks for replying. We're half-way there with your solution. The get URL bit works. I used alert(theTab) to check that the var had got the right value which it had. The problem is that the code that sets defaultTab to the value of theTab isn't working.

var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", { defaultTab: theTab });

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved