sessions with jquery tabs

phillystyle123
phillystyle123 used Ask the Experts™
on
I'm using jquery tabs on this page:

http://dev.roydent.com/products.asp
User id= roydentdev
Password= roydent5100

this latest code that merwetta1 has so kindly developed for me - has been altered so a site visitor can click on a product listed on a tab, go to that product page then browse back to the jquery tabs and the tab that contains listing of the product they navigated to will load (instead of the default 1st tab).

this was working perfectly. but, there seems to be some sort of bug in the code - meaning that sometimes the tabs don't load at all (see screen shot) and sometimes they do. I've attached the js code as well.



 screen shot of jquery tabs not loading screen shot of jquery tabs not loading the way it's supposed to loook
<script type="text/javascript">
	
$(document).ready(function(){

	var Url = document.location.href.split('#');
	var Anchor = Url[1];
	var SelectedCookie = getCookie('SelectedCookie');
	var SelectedTabs = SelectedCookie.split(':');
	var SelectedHTab = SelectedTabs[0];
	var SelectedVTab = SelectedTabs[1];
	
	if (!SelectedCookie)
	{
		if (Anchor == 'tabsv-1')  SelectedHTab = 1;
		else if (Anchor == 'tabsv-2')  SelectedHTab = 1;
		else if (Anchor == 'tabsv-3')  SelectedHTab = 2;
		else if (Anchor == 'tabsv-4')  SelectedHTab = 2;
	}

	var htabs = $("#tabs").tabs();

	$("#tabs2").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
	$("#tabs2 li").removeClass('ui-corner-top').addClass('ui-corner-left');

	$("#tabs3").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
	$("#tabs3 li").removeClass('ui-corner-top').addClass('ui-corner-left');

//	tabs4 is not implemented yet
//	$("#tabs4").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
//	$("#tabs4 li").removeClass('ui-corner-top').addClass('ui-corner-left');

	if (SelectedHTab)
	{
//		alert("SelectedHTab="+SelectedHTab+", SelectedVTab="+SelectedVTab);	// uncomment this to see tab states retrieved from cookie
		htabs.tabs('select', '#tabs-'+SelectedHTab);
		if (SelectedVTab)
		{
			if (SelectedHTab == 1) $("#tabs2").tabs('select', '#tabsv-'+SelectedVTab);
			else if (SelectedHTab == 2)
			{
				SelectedVTab = Number(SelectedVTab) + 2;	// tabs3 uses "3" and "4" for names
				$("#tabs3").tabs('select', '#tabsv-'+SelectedVTab);
			}
		}
	}

	saveTab = function saveTab()
	{
		SelectedVTab = 0;
		SelectedHTab = htabs.tabs('option', 'selected') + 1;	// have to add 1 because tab numbering starts at 0
		if (SelectedHTab == 1)  SelectedVTab = $("#tabs2").tabs('option', 'selected') + 1;
		else if (SelectedHTab == 2)  SelectedVTab = $("#tabs3").tabs('option', 'selected') + 1;
		
		setCookie('SelectedCookie',SelectedHTab + ":" + SelectedVTab,1);	// the last argument is the number of days to keep the cookie
//		alert('setting cookie to '+SelectedHTab + ":" + SelectedVTab);  // uncomment this to get an alert showing cookie being set
	}

	$(window).unload( function () { saveTab(); } );

});

function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0) 
	{
		begin = document.cookie.indexOf(NameOfCookie+"="); 
		if (begin != -1) 
		{
			begin += NameOfCookie.length+1; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		} 
	}
	return null; 
}

function setCookie(NameOfCookie, value, expiredays) 
{
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + 
		((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

	</script>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
try to move your css files
<link type="text/css" href="jquery-tabs/demos.css" rel="stylesheet" />
above the jquery files declaration
and see if there are any changes.

Author

Commented:
seems to have done the trick- thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial