activate tab panel based on xml data

One change is when a team is up to bat I need the tab to be activated based on visitor up to bat or hometeam up to bat. The tab i'm talking about is tab panel with table of players.
So I started thinking I just want this to occur one time a inning. So What if I used 3 outs then start off with a# visitor then next 3 outs b# home get activated. or do you think nextbatter team id and if nextbatter team id = visitor #a becomes active else if nextbatter team id = home then b# becomes active. What do you think what approach is better or do you have a better idea. Sample code I'm just not sure of setting variable part TO COMPARE with team at bat.

var intOuts = d.find('Play').attr("Outs") || 0;
        if (intOuts === "3") {
    var sTeam = objNode.attributes.getNamedItem('vh').value;	
if (sTeam == 'A')	
 $mytabs.tabs('select', 0);         
 else if if (sTeam == 'H')	
 $mytabs.tabs('select', 1);         
 

        }
        

Open in new window


or  

 var players = $(data).find("Player");
		 var d = $(data);
   var Batter = d.find('NextBatter');
        if (Batter.size() > 0) {

          var nextbatterteam = Batter.attr('TeamID');
          var nextbatterid = Batter.attr('ID');
 var sTeam = objNode.attributes.getNamedItem('vh').value;	

}
		}

Open in new window

LineupcardGame2.html
37504.xml
development-bundle.zip
powerztomAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
nap0leonConnect With a Mentor Commented:
Here is the correct syntax for selecting the team's tab

				if (nextbatterteam == awayTeamID) { 
					console.log('select Away team');
					$("#myTabs").tabs('select',0)
				} else {
					console.log('select Home team');
					$("#myTabs").tabs('select',1)
				}

Open in new window

0
 
nap0leonCommented:
Since the next batter's team ID is not know until after the 3rd out, that would be the most reliable indicator to use and is a check that could be run every time you poll the XML.

Not saying this would happen, but it conceivably could... If you were to switch innings when the Out total became "3", what happens if the XML file was actually incorrect and they change it back to "2 outs"?

Anyway... just seems safer to use the ID of the next batter, since that will always tell you the team that is currently (or on their way up) to bat.

var d = $(data);
var Batter = d.find('NextBatter');
if (Batter.size() > 0) {
	var nextbatterteam = Batter.attr('TeamID');
	var nextbatterid = Batter.attr('ID');
}

Open in new window


Now that you have the ID of the team that is headed up to bat, you can use the team's ID to find out home or away to make sure the correct tab is active.

Edit:  From a usability perspective, you should probably only use this to activate a tab when the page first loads and when the Next Batter's team is different from the most recent "Current Batter". (Since a user can manually switch which team's panel is active, you don't want to keep switching it back to the the "at bat" team every 3 seconds.  only switch it when the at-bat team changes.)
0
 
powerztomAuthor Commented:
I 'm trying to construct the statement but I'm having a issue check it out

   function SetTab() {
	 var d = $(data);
   var Batter = d.find('NextBatter');
        if (Batter.size() > 0) {

          var nextbatterteam = Batter.attr('TeamID');
          var nextbatterid = Batter.attr('ID');
		  var Batter = d.find('NextBatter');
        if (Batter.size() > 0) {

          var batterteam = Batter.attr('TeamID');
          var batterid = Batter.attr('ID');
		  if (nextbatterid == batterteamid); 
		  $mytabs.tabs('select', 0);
		  else if
		   $mytabs.tabs('select', 1);
		}
		}
		}
}

Open in new window

0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
nap0leonCommented:
The next batter's team will always be the same as the current batter's team (unless there is no current batter... Maybe that will work in your comparison), but I would go with finding the "home team ID" or "away team ID" and use that in your comparison for which tab to select (you probably only need one team's ID for tab-selection, but it may be useful elsewhere as you add more functionality)
0
 
powerztomAuthor Commented:
You got me headed in the right path Can you write code?
0
 
nap0leonCommented:
I adjusted the pathing to match my local system and also removed the interval timer.

I don't know how to work the UI selectors you are trying to use - they threw an error... but I have the code working for determining which team is home or away and comparing the next batter's team.  Messages are in console.log.  So where you see
console.log('select Away team');

Open in new window

that's where you want activate the away team's tab, etc.
LineupcardGame.html
0
 
powerztomAuthor Commented:
Thank You Sir. Great work
0
 
powerztomAuthor Commented:
It broke the code I'll give you a zip of everything you need to test. The xml file is Home so activated tab such be the White Sox. What happened all the players were gone but now you have all necessary files. Your help is greatly appreciated
Lineup-Card1.zip
0
 
nap0leonCommented:
A few issues...
1- the pathing to the jquery-ui-1.8.9.custom.css was incorrect
2- the pathing to the xml file was incorrect
3- the name of the xml file was incorrect
4- you did not have any (?) of the changes I made... like setting the homeTeamID and awayTeamID or the changes to select the correct tab
5- the xml file you sent has the Cubs at bat, not the WhiteSox, so the Cubs tab is activated.

Attached is the updated HTML file that you should be able to drop into the folder that you zipped.
LineupcardGame.html
0
 
powerztomAuthor Commented:
You did it great work. I am grateful
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.