javascript - How to read property of Object -


i selecting value drop down , want use in following way. here returning value drop down in variable selectedtext.

  <p style="font-size:150%;margin-left:20%; margin-top:50px"> sources :          <select id="drop" name="drop">              <option value="0">select source</option>              <option value="1">rbsk</option>              <option value="2">midrs</option>              <option value="3">atm </option>              <option value="4">rt </option>          </select>            <script type="text/javascript">              $(function () {                  $("#drop").change(function () {         var  selectedtext = $(this).find("option:selected").text();  //var selectedvalue = $(this).val();  //alert("selected text: " + selectedtext + " value: " + selectedvalue);                  });              });          </script>

now want use value here:

var demapping = {              rbsk: {'dsuid': 'tdtwluxcq8r', rootnodename: 'rbsk_gis_indicator', orgunittagname: 'mctscode', des: [                  {                      xmlid: "childhood_diseases_0_6_female",                      dataelement: "ov163sbcj0n",                      categoryoptioncombo: "cmzbo9ld8pj"                  }                  ]},             atm:{},             abc:{},             def:{}  };

i want use selectedtext in way:

demapping.rbsk.des[5].categoryoptioncombo; //here return correct value of 6th element in des array. 

now want replace rbsk selectedtext user selects dropdown.

so if user selects atm should return values related atm. demapping.selectedtext.des[5].categoryoptioncombo; becomes demapping.atm.des[5].categoryoptioncombo; if user selects atm dropdown

can help?

your question not clear had tried understand.

demapping.rbsk.des[5].categoryoptioncombo; //here return correct value of 6th element in des array.

for des there not 6 object not work.

here working snippet replacing works option rbsk because other options don't have data.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <p style="font-size:150%;margin-left:20%; margin-top:50px"> sources :  <select id="drop" name="drop">      <option value="0">select source</option>      <option value="rbsk">rbsk</option>      <option value="midrs">midrs</option>      <option value="atm">atm</option>      <option value="rt">rt</option>  </select>  </p>  <script type="text/javascript">  var demapping = {      rbsk: {'dsuid': 'tdtwluxcq8r', rootnodename: 'rbsk_gis_indicator', orgunittagname: 'mctscode', des: [      {          xmlid: "childhood_diseases_0_6_female",          dataelement: "ov163sbcj0n",          categoryoptioncombo: "cmzbo9ld8pj"      }      ]},      atm:{},      abc:{},      def:{}  };  $(function () {      $("#drop").change(function () {          var selectedtext = $(this).find("option:selected").text();          alert(demapping[selectedtext].des[0].categoryoptioncombo);      });  });  </script>


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -