Tom Powers
asked on
Increment a value from a xml file
I had someone on EE look at this and I thought he had solved it. It has to do with a html table that contains Innings and runs for each inning. What is soppossed to happen is when Extra Innings are needed the 1 or 1st inning in the table shifts to the left and where the 9 or 9th inning is it becomes 10 or 10th everything shifts to the right. That is what is suppossed to happen but I just tested it with a live game and the table header starts out with negative numbers to the right and 1 inning is where the 9th should be as each inning happens 1 slides down to next cell to the right and 2 comes out. Image 1 is what should start out like
Image2 is what the messed up code looks like and Image3 is what table should look like if extra innings. I attached a xml file and messed up html. Please help it is opening day.
If it sounds confusing look at images Any questions please ask
ScoreB2.html
37260.xml
Image1.png
Image2.png
Image3.png
Image2 is what the messed up code looks like and Image3 is what table should look like if extra innings. I attached a xml file and messed up html. Please help it is opening day.
If it sounds confusing look at images Any questions please ask
ScoreB2.html
37260.xml
Image1.png
Image2.png
Image3.png
ASKER
Tried it it didnot work All I need is for the 9 to turn into 10 if game goes to the tenth and 1 disappear and all numbers slide down to the left and of course if extra innings continue I need the above action to take place. The guy that did it half way got it right but at the start of the game the innings read -8,-7,-6,-5,-4,-3,-2,-1,0 1 I understand what he was trying to do but I cann't have the scoreboard reading negative values no client is going to go with that I'll attach the original scoreboard that works but needs the extra innings to work.Just create extra innings in xml file to test
Scoreboard.htm
38822.xml
Scoreboard.htm
38822.xml
It worked in my test. arrLinescores "A" length equals 6 in your original posted code. Subtract 10 and you have -4. That's where your negative numbers are coming from. That's why it makes no sense to me that you are using arrLinescores "A" instead of "I" for the number of innings.
If you can explain the logic of why you use arrLinescores "A" to me I'll take another look. Otherwise I have nothing else to offer. As I said, using arrLinescores "I" worked in my test and makes logical sense to me.
If you can explain the logic of why you use arrLinescores "A" to me I'll take another look. Otherwise I have nothing else to offer. As I said, using arrLinescores "I" worked in my test and makes logical sense to me.
ASKER
I'm down with using I INSTEAD OF A I didn't write that code a member of EE wrote the code I'm just learning a beginner so I cannot explain reason for A What I need is for this to work Please just explain what I need to change and I'll do it.
Here, try this:
var innings = objDocNode.attributes.getNamedItem('Inning').value;
var offSet = innings;
if (innings>9){
offSet = innings - 9;
}
for (var i=2; i<11; i++) {
$('#txtInning').closest('tr').find('td:nth-child('+i+')>div').html(i+offSet-1);
}
ASKER
Tommyboy,
The A I believe was for Away meaning Away team When I tried your code It didn't load anything I'll attach Html and XML Maybe I put your code in the wrong place again I'm a beginer
Scoreboard2.htm
33661.xml
The A I believe was for Away meaning Away team When I tried your code It didn't load anything I'll attach Html and XML Maybe I put your code in the wrong place again I'm a beginer
Scoreboard2.htm
33661.xml
Your script is broken. One reason may be that your xml url has two periods --url: "33661..xml".
Rather than have me search for the problem, how about I post my working example.
Rather than have me search for the problem, how about I post my working example.
<script type="text/javascript">
//var counterXml = 0;
var txtPitcher = "", txtBatter = "", txtOuts = "";
var srcBatter = "", srcBatterTeam = "", srcPitcher = "", srcPitcherTeam = "";
var arrLinescores = {I:[], "H":new Array(),"A":new Array()};
var arrStrikeImages = ['Dot2.png', 'Strike1.png', 'Strike2.png', 'Strike3.png'];
function loadData() {
$.ajax({
type: "GET",
url: "38822.xml",
dataType: "xml",
success: function(data, textStatus, jqXHR){
var objDocNode = (jqXHR.responseXML ? jqXHR.responseXML : $.parseXML(jqXHR.responseText)).documentElement;
var intOuts = objDocNode.attributes.getNamedItem("Outs") ? objDocNode.attributes.getNamedItem("Outs").value : 0;
$('#txtOuts').val("outs: " + intOuts);
$('#Outs').attr('src', arrStrikeImages[intOuts]);
var intStrikes = objDocNode.attributes.getNamedItem("Strikes") ? objDocNode.attributes.getNamedItem("Strikes").value : 0;
$('#Strikes').attr('src', arrStrikeImages[intStrikes]);
for(var i=1;i<10;i++){
arrLinescores.I[i] = i;
}
var colNodes = objDocNode.childNodes;
for (var i=0; i < colNodes.length; i++) {
var objNode = colNodes[i];
switch(objNode.nodeName) {
case 'Team':
var sTeam = objNode.attributes.getNamedItem('vh').value;
if ("undefined" != arrLinescores[sTeam]) {
arrLinescores[sTeam].N = objNode.attributes.getNamedItem('name').value;
for (var ii=0; ii < objNode.childNodes.length; ii++) {
var objSubNode = objNode.childNodes[ii];
if (objSubNode.nodeName == 'Linescore') {
for (var iii=0; iii < objSubNode.childNodes.length; iii++) {
var objSubSubNode = objSubNode.childNodes[iii];
if (objSubSubNode.nodeName == 'Lineinn') {
arrLinescores[sTeam][objSubSubNode.attributes.getNamedItem('inn').value*1] = objSubSubNode.attributes.getNamedItem('score').value;
}
}
arrLinescores[sTeam].R = objSubNode.attributes.getNamedItem('Runs').value;
arrLinescores[sTeam].H = objSubNode.attributes.getNamedItem('Hits').value;
arrLinescores[sTeam].E = objSubNode.attributes.getNamedItem('Errors').value;
}
}
}
break;
default:
break;
}
}
var innings = objDocNode.attributes.getNamedItem('Inning').value;
var offSet = parseInt(innings);
if (innings>9){
offSet = innings - 9;
}
for (var i=2; i<11; i++) {
$('#txtInning').closest('tr').find('td:nth-child('+i+')>div').html(i+offSet-1);
}
$('#txtVisitor').closest('tr').find('td:nth-child(1)>div').html(arrLinescores['A'].N);
$('#txtHometeam').closest('tr').find('td:nth-child(1)>div').html(arrLinescores['H'].N);
for (var i=10; i>0; i--) {
$('#txtVisitor').closest('tr').find('td:nth-child('+(i+1)+')>div').html(arrLinescores['A'][i+offSet]);
$('#txtHometeam').closest('tr').find('td:nth-child('+(i+1)+')>div').html(arrLinescores['H'][i+offSet]);
}
var lblTotal = "R;H;E".split(';');
for (var i=0; i<lblTotal.length; i++) {
$('#txtVisitor').closest('tr').find('td:nth-child('+(i+11)+')>div').html(arrLinescores['A'][lblTotal[i]]);
$('#txtHometeam').closest('tr').find('td:nth-child('+(i+11)+')>div').html(arrLinescores['H'][lblTotal[i]]);
}
colNodes = objDocNode.getElementsByTagName("narrative");
var msg = "";
for (var i=0; i < colNodes.length; i++) {
var objNode = colNodes[i];
msg += objNode.nodeName + ": " + objNode.attributes.getNamedItem("text").value + "\n";
}
$('#txtNarrative').val(msg);
if ("FINAL" == objDocNode.attributes.getNamedItem("Status").value.toUpperCase()) { clearInterval(myVar); }
// ++counterXml;
},
error: function() {
//counterXml = -1;
}
});
}
</script>
ASKER
Thanks for coding it but the Page does not pull any xml into it I attached html and xml so you can see what I see.
Scoreboard2.htm
33661.xml
Scoreboard2.htm
33661.xml
It's looking for the value of variable "t" on line 263. Seems to be a couple of lines of code missing, perhaps:
var d=new Date();
var t=d.toLocaleTimeString();
Also,
<body onLoad="addHandle(document .getElemen tsByTagNam e('body'). item(0), window);">
addHandle is undefined. Did you remove a .js file that was included before?
And, 33661.xml is not a valid xml file, syntax errors.
And, you have no jquery library loaded.
And, you have removed id="txtInning" from the table row.
If you keep changing the markup, we will never get there.
var d=new Date();
var t=d.toLocaleTimeString();
Also,
<body onLoad="addHandle(document
addHandle is undefined. Did you remove a .js file that was included before?
And, 33661.xml is not a valid xml file, syntax errors.
And, you have no jquery library loaded.
And, you have removed id="txtInning" from the table row.
If you keep changing the markup, we will never get there.
ASKER
Yo I tried your code but the scoreboard didnot pull in any xml data. Do you know why
Scoreboard2.htm
38822.xml
Scoreboard2.htm
38822.xml
Yes.
You have no jquery library loaded. Jquery will not work.
And, you have removed id="txtInning" from the table header row. The code has no way of modifying a table row it cannot find.
You have no jquery library loaded. Jquery will not work.
And, you have removed id="txtInning" from the table header row. The code has no way of modifying a table row it cannot find.
ASKER
I added Jquery I'm not sure about adding txtInning to table row How would I code it and Will that allow me to pull Extra Innings from xml file.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks Tommy Boy you got it right my bad
Open in new window
I would think you would want innings from arrLinescores. Also, why subtract 10 when there are 9 innings in a typical game?Try this:
Open in new window
I also don't understand where the 11 comes from in the loop. Surely there could be more than ten innings in a baseball game. Maybe it should be
Open in new window