?
Solved

activate tab panel based on xml data

Posted on 2013-05-28
10
Medium Priority
?
260 Views
Last Modified: 2013-05-31
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
0
Comment
Question by:powerztom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 18

Expert Comment

by:nap0leon
ID: 39202287
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
 

Author Comment

by:powerztom
ID: 39205035
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
 
LVL 18

Expert Comment

by:nap0leon
ID: 39205515
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:powerztom
ID: 39206238
You got me headed in the right path Can you write code?
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 39209218
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
 
LVL 18

Accepted Solution

by:
nap0leon earned 2000 total points
ID: 39209230
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
 

Author Closing Comment

by:powerztom
ID: 39210649
Thank You Sir. Great work
0
 

Author Comment

by:powerztom
ID: 39211357
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
 
LVL 18

Expert Comment

by:nap0leon
ID: 39211416
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
 

Author Comment

by:powerztom
ID: 39211588
You did it great work. I am grateful
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question