BIG EDIT 11/19/2012
So, my problem is here.
I’m trying to develop a simple cart app with jQuery and XML.
Everything’s OK, but only if the name of My pizz only contains numbers… WHY ???
Try yourself, you’ll constat that only the “66666” pizza is working… WHY ???
Here is my jS code:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "example.xml",
dataType: ($.browser.msie) ? "text" : "xml",
success: function(xml) {
$(xml).find('row').each(function(){
var Col0 = $(this).find('nompizz').text();
var Col1 = $(this).find('petit').text();
var Col2 = $(this).find('moyen').text();
var Col3 = $(this).find('grand').text();
$('<tr id="bar"></tr>').html('<th class="title">'+Col0+'</th><td onclick="DisPlay('+Col1+');GetName('+Col0+');">'+Col1+'€</td><td onclick="DisPlay('+Col2+');GetName('+Col0+');">'+Col2+'€</td><td onclick="DisPlay('+Col3+');GetName('+Col0+');">'+Col3+'€</td>').appendTo('#pizzas');
});
}
});
});
function DisPlay(Figure) {
var Display = document.getElementById('Display');
if (Figure === null) {
Display.value = Figure;
}
else {
Display.value += "+"+Figure;
Screen = Display.value
result = eval(Screen);
Display.value =result;
}
Figure = null;
}
function GetName(NomPizz) {
var $newItem = '<li>Ajouté: '+NomPizz+'</li>';
$('.theList').append($newItem);
}
And here my XML:
<?xml version="1.0"?>
<document>
<row>
<nompizz>66666</nompizz>
<petit>10</petit >
<moyen>15</moyen >
<grand>20</grand>
</row>
<row>
<nompizz>Letters</nompizz >
<petit>15</petit >
<moyen>20</moyen >
<grand>25</grand>
</row>
</document>
I think your problem is that your
GetAnswer()function is agnostic to the rest of the application. It doesn’t know what was clicked. I think that the easiest thing to do would be to just add thenomparameter to yourDisPlay()function call. Like this: (remove the linefeeds)Then your
DisPlay(Figure)becomes:A word about global variables vs. non-global variables. If you ‘var’ something inside a function, that variable is local to that function. It seems like you were mixing and matching your vars. For more on that read this post.
EDIT:
After your new edits you are only getting numeric pizza names because you need to have quotes int he proper place. Try changing all your
GetName('+Col0+');toGetName(\''+Col0+'\');So that whole line would read: