Hi Dave, it worked great with a little bit of modification.
Thank you very, very much! And I even learned something new today then :) Thanks again eid Dave Probert wrote: > Hi eid, > > I've taken a look at what you are trying to do and I think there are > two aspects that need to be 'corrected'. > > 1.) In the JSON, there is no need for an array of items - remove the > [ & ] after 'items'. items is then an object with elements called > 'lanceOfMitraDivinity', 'wrathOfMitraDivinity', etc. Much easier to > handle. > > 2.) To setup the buttons you would be better like this (not the only > way to do it, but this works!): > $.getJSON('featsCalculator/priestofmitra.js', function(data) > { > $('.featButton').click(function() > { > var t = $(this).attr('id'); > if(data.items[t]) > { > $('#state').html(data.items[t].description.base); > } > }); > }); > > You can use the items part of the json like an array, even though it > is an object - because all objects can be accessed either via the dot > operator (.) or using square brackets ([]). > > Here is some tested code that works with the modified json you > provided. Just cut and paste (modify any filenames and paths) and try > it. > > ----- start of code > > <script type="text/javascript" src="js/jquery.js"></script> > <script> > $(document).ready(function() > { > $.getJSON('featsCalculator/priestofmitra.js', function(data) > { > $('.featButton').click(function() > { > var t = $(this).attr('id'); > if(data.items[t]) > { > $('#state').html(data.items[t].description.base); > } > }); > }); > }); > </script> > <div id='state'></div> > <div class='featButton' id='lanceOfMitraDivinity'>Lanc</div> > <div class='featButton' id='piercingLanceDivinity'>Pier</div> > <div class='featButton' id='condemnationDivinity'>Cond</div> > > ----- end of code > > Hope that helps a bit. > > Cheers, > Dave >