2

I am building a web-based tool for the role-playing game GURPS. Data is maintained in several XML files that are loaded into arrays. Based on changes the user makes, data is re-populated into various spans, inputs and dropdowns from the arrays. No problem so far.

To give the user more feedback, I have a added an anchor that does a hover pop-up that shows the details of the current weapon. For the initial coding, these values were hard-coded while I worked out the rendering issues. Still no problems yet.

Now I am trying to actually populate the hover pop-up with real data. I can not get it to load the real data into the span! I have debugged the function and am certain that I have extracted the data I want. I have used similar lines of code to populate other parts of the web page.

Specifics: I want to replace the "aa" in the span below:

<span id="weaponName1" name="weaponName1" class="weaponName">aa</span><img src="Images/Firearms/Makarov_Suppressed.jpg">

The code I am using to try to re-populate the span is:

function loadWeaponStats(person, weaponID) {
// Load stats of the current weapon into the "Details" anchor fly-out
for (xx1=0; xx1<WeaponsArray.length; xx1++) {
    if (weaponID == WeaponsArray[xx1][0]) {
        weaponName = WeaponsArray[xx1][1];
        alert("weaponName: "+weaponName+"\nperson: "+person);
        $("#weaponName"+person).val(weaponName);
        xx1 = WeaponsArray.length;  // Kill the loop
    }
}

}

The alert() is simply to confirm that I have the correct data. The following line should re-populate the span, but it does not.

All HTML, CSS & JavaScript can be found at GURPS Combat Calculator

Pulling out what little hair I have left.

Thanks

1 Answers1

0

You can also do as below:

     $("#weaponName"+person).text(weaponName);

you can't use Val() method here.

Bhushan Firake
  • 9,338
  • 5
  • 44
  • 79
  • Thanks!!! That got it, though I am confused why all my other code works but this does not. – user1889833 Dec 09 '12 at 18:09
  • @user1889833: Is the other code on the same page? It might be possible that the code is not getting the JQuery file or you may have an error...Accept the answer as your question is solved. – Bhushan Firake Dec 09 '12 at 18:12
  • @user1889833: You can put the code that is not working and you will get the problem... – Bhushan Firake Dec 09 '12 at 18:13