Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

activate tab panel based on xml data

Posted on 2013-05-28
10
Medium Priority
?
264 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

971 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