0

Everything works in the code below but I would like to take "filterItemID[0].Zone1", remove "Zone1" and insert the var getPriceID. I've tried doing this multiple ways but nothing seems to work.

function jsonParser(json) {
  $.getJSON('../../data/empdata.json', function(data) {
    var filterItemID = $.grep(data, function(element, index) {
      return element.ItemId == findItemID;
    });
    var getPriceID = $("#PriceIDs").val();

    var UpdateCostField = filterItemID[0].Zone1;
    $(contentpaneIFParent).find("#Cost").append().val(UpdateCostField);
    $(contentpaneIF).css('background-color', 'transparent');

  });

}
Tibrogargan
  • 4,508
  • 3
  • 19
  • 38
Luke
  • 1
  • 1
  • You're trying to use `filterItemID` before the AJAX callback function executes. – Barmar Nov 10 '16 at 23:25
  • Returning something from the callback function is useless, nothing uses it. – Barmar Nov 10 '16 at 23:26
  • Now that I've cleaned up the indentation, I see that I was wrong. It's in the right scope. – Barmar Nov 10 '16 at 23:28
  • Show a sample of the JSON, and what you're trying to do with it. It's not clear what you mean by remove `Zone1` and insert `getPriceID`. – Barmar Nov 10 '16 at 23:30
  • Your question is ambiguous, but I think what you want is this: `var UpdateCostField = filterItemID[0][getPriceID];` – Tibrogargan Nov 10 '16 at 23:31
  • What is `.append()` supposed to do? You're not appending anything. – Barmar Nov 10 '16 at 23:31
  • Thank you Tibrogargan! I had tried var UpdateCostField = filterItemID[0][getPriceID]; but.. I added a period between filterItemID[0] and [getPriceID] like a dummy. Thank you! That worked.. – Luke Nov 10 '16 at 23:37

0 Answers0