1

I have a few JSON objects, which I'm fetching data from, but I'd really like to be able to get some specific data, depending on my selection in a selection container, but I'm not sure how tell my function which selection I've chosen. Here's what I've tried so far:

var parsedData = JSON.parse(someData);

    $(parsedData).each(function() {
        var m = document.getElementById("measurements"); //My selection container
        var selectedValue = m.options[m.selectedIndex].text; //What's currently selected

        var data = this.selectedValue; //This doesn't work
        var data = this.Id //This works
        console.log(newData);
    });

Any hint appreciated.

Khaine775
  • 2,715
  • 8
  • 22
  • 51
  • 2
    `this[selectedValue]` – Dr.Molle Oct 16 '15 at 11:32
  • That was it. Thanks! – Khaine775 Oct 16 '15 at 11:35
  • I'm assuming `this.selectedValue` contains server side value and `selectedValue` contains user entered value, right? If yes, I would suggest print entire parsedData and check if you are receiving selectedValue from there. Also if you can create a JSFiddle, it would be easier to understand/find solution to the issue – Rajesh Oct 16 '15 at 11:39
  • @Dr.Molle is there a difference between `object.property` and `object[property]`? I used to consider them one and the same. – Rajesh Oct 16 '15 at 11:43
  • 2
    yes, in `object[property]` a variable `property` is expected(which contains the name of the property), while in `object.property` the name of the property is `property` . So `object.property` is equal to `object['property']` (Note the quotes). But when there exists a variable `property` with the value `property`, then `object.property` and `object[property]` would be equal. – Dr.Molle Oct 16 '15 at 11:47

0 Answers0