I'm trying to figure out how to make the following code work:

     <ul> <li id='anvil1' class='locked' onclick='anvil1.countCheck("anvil1", "defense", 10, event.button);'>+10 Defensive Ability</li> <li id='anvil4' class='locked' onclick='anvil4.countCheck("anvil4", "[\"defense\", \"constitution\"]", [10, 20], event.button);'>+15 Defensive Ability <br />+20 Constitution</li> </ul>

These links are accessing methods from the the star object. I need the 2nd and 3rd parameters to be arrays, because they have a variable number of values. For instance, the first star, anvil1, has one stat (defense) and one value (10). The fourth star has two stats (defense, constitution) and two values (10, 20). I believe the number of stats/values can go up to 3.

So far, if I try to call stats[0] the value that's returned is simply the first letter?

alert('Stats: ' + stats[0]); results in an alert box with Stats: d I'm not sure how to fix this, and any advice would be greatly appreciated!

Recommended Answers

All 4 Replies

Please properly format your code, indendented appropriately. I won't comment on code like this...

<ul> 
  <li id='anvil1' class='locked' onclick='anvil1.countCheck("anvil1", "defense", 10, event.button);'>+10 Defensive Ability</li>
  <li id='anvil4' class='locked' onclick='anvil4.countCheck("anvil4", "[\"defense\", \"constitution\"]", [10, 20], event.button);'>+15 Defensive Ability <br />+20 Constitution</li> 
</ul>

I was sending a string instead of an array. Solution:

<ul> 
  <li id='anvil1' class='locked' onclick='anvil1.countCheck("anvil1", ["defense"], [10], event.button);'>+10 Defensive Ability</li>
  <li id='anvil4' class='locked' onclick='anvil4.countCheck("anvil4", ["defense", "constitution"], [10, 20], event.button);'>+15 Defensive Ability <br />+20 Constitution</li> 
</ul>
Member Avatar for diafol

Instead of sending 2 arrays, you could send one object:

["defence"],[10] could be ONE var: {"defence": 10}
["defence","constitution"],[15,20] could be ONE var: {"defence": 15, "constitution": 20}

Then you don't need a check to see if lengths of the two arrays are equal.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.