This function is called when an element is clicked. It creates a string based on what element was clicked, and then looks up the value associated with that string in a JSON object. It then alerts that value. Here's how it looks:
function alertHelp(){
var option = $(this).context.parentNode.textContent.substring(0, $(this).context.parentNode.textContent.length - 2);
$.getJSON("Messages.json", function(json, option) {
alert(json[option]);
});
}
What I've found is that option is set correctly, but then when passed to the function with the alert is changed. If I alert(option) right before alert(json[object]);, I get an alert that simply says "success". Not sure what's up with that. alert(json[option]) simply alerts "undefined".
Here's Messages.json:
{
"Space Control": "Red = a square black controls. Green = a square white controls. Yellow = a square contested by both players",
"Legal Moves": "Click on a piece and a blue dot will appear on all the squares that piece can move to",
"PieceFlair": "When you move a piece, all the pieces that come under attack as a direct result of the piece you moved will pulse white",
"Forks": "All the moves that would result in a simultaneous attack of two pieces are shown",
"Pins": "Not yet implemented"
}
alert(option);shows "success" is because you've redefined it as the second parameter to the callback:, function(json, option) {. Either don't include it (because I don't think you need it), or change the parameter name, function(json) {. Then,alert(option);to make sure it's set properly. If it looks right but isn't working, try trimming it