javascript - Compare HTML element with JSON array and replace -
so i've been trying while no luck far. want accomplish is, after selecting value drop down, value should compared json multi-dimensional array. if matches, there html elements on webpage content needs replaced corresponding json values.
here i've been working far (link)
<select onchange="executeme(this)" id="selectopt"> <option value="445">choose...</option> <option value="445">daisy</option> <option value="446">romeo</option> </select> <br/><br/><br/> <label id="entity_id">replacethis</label>
so in fiddle, if user chooses "daisy" dropdown, (the first array has daisy in it) corresponding value set array should displayed in each of html element on webpage.
i can utilize javascript this. in advance guys...
you've got problems. first, string map function massive , won't pass equality check alternative value. additionally, anonymous function going homecoming first value , not iterate through for
loop properly. there's no correlation between select alternative values/labels , items in array. seek this:
function executeme(select) { var myselect = document.getelementbyid("selectopt"); var selectoption = myselect.options[myselect.selectedindex].innerhtml; var = thearray.length, obj, index, val; while (i--) { obj = thearray[i]; (index in obj) { val = obj[index]; //following matches on both keys , values, if //want values delete sec part of check if (val == selectoption || index == selectoption) { var string = '', prop; (prop in obj) { string += prop + ': ' + obj[prop].tostring() + '<br>'; } document.getelementbyid('entity_id').innerhtml = string; } } } }
if isn't need allow me know comment.
javascript arrays json multidimensional-array
No comments:
Post a Comment