I am working with a JSON array and trying to do a simple parse and cannot get the following line of code to work:
document.getElementById('MapId').value = obj[0].properties.OBJECTID;
This does not populate the input box on the form.
Should I be using stringify instead?
Here's my document below
<!DOCTYPE html>
<html>
<body>
<h2>Create Object from JSON String</h2>
<p id="demo"></p>
<form>
<h1>
Map Title
</h1>
Id:<br>
<input type="text" name="MapId" id="MapId">
</form>
<script>
var obj = JSON.parse('[
{
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-80.38001898676157,
43.41005948475032
],
[
-80.38005586713552,
43.41005583130982
],
[
-80.38005754351616,
43.410064843129305
],
[
-80.3800206631422,
43.41006849656927
],
[
-80.38001898676157,
43.41005948475032
]
]
]
},
"type": "Feature",
"properties": {
"DIRECTION": "0",
"OBJECTID": 1309,
"RANGE": "000",
"SECTION_": "15",
"SHAPE_AREA": 3.030074,
"SHAPE_LENG": 8.040001
},
"id": 97,
"layer": {
"id": "cemeterypl3-6k66v9",
"type": "fill",
"source": "composite",
"source-layer": "CemeteryPL3-6k66v9",
"layout": {
"visibility": "visible"
},
"paint": {
"fill-opacity": 0.5,
"fill-color": "hsl(107, 50%, 27%)"
}
}
}
]');
document.getElementById('MapId').value = obj[0].properties.OBJECTID;
</script>
</body>
</html>