When i am selecting the city in first select box show the city relented data
how to populate the the json when selecting city in first drop down and how to show the relented data when select the different city?
this is html
$(document).ready(function() {
var cityData = [{
cityName: 'Bengaluru',
value: "Bengaluru",
data: [{
movieName: 'ABC',
theaterName: 'Tulsi Theatre'
},
{
movieName: 'DEF',
theaterName: 'PVR'
},
{
movieName: 'GHI',
theaterName: 'Srinivasa Theatre'
}
]
},
{
cityName: 'Hyderabad',
value: "Hyderabad",
data: [{
movieName: '123',
theaterName: 'Theatre1'
},
{
movieName: '456',
theaterName: 'PVR2'
},
{
movieName: '789',
theaterName: 'Theatre3'
}
]
},
{
cityName: 'Guntur',
value: "Guntur",
data: [{
movieName: 'ABC1',
theaterName: 'Theatre4'
},
{
movieName: 'DEF2',
theaterName: 'PVR3'
},
{
movieName: 'GHI3',
theaterName: 'Theatre5'
}
]
},
{
cityName: 'Ongole',
value: "Ongole",
data: 'currently not available'
}
];
$("#selectCity").on('change', function() {
var locations = cityData[$(this).val()];
var locationString = 'locations';
console.log(locations)
$.each(locations, function(i, item) {
console.log(JSON.stringify(item));
// OUCH!!!
locationString += '<option value="' + item.id + '">' + item.name + '</option>';
});
//console.log(locationString)
$('#secondselectbox').html(locationString);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="UserData">
<h1>MyMovie-Ticket-Booking</h1>
<select class="selectCity" id="selectCity">
<option value="City">Select City</option>
<option value="Bengaluru">Bengaluru</option>
<option value="Hyderabad">Hyderabad</option>
<option value="Guntur">Guntur</option>
<option value="Ongole">Ongole</option>
</select>
<span id="welcome"> </span>
</div>
<div>
<select id="secondselectbox"></select>
<select id="secondselectbox"></select>
</div>
when i am selecting the city Bangalore show the Bangalore theater list and movie list but it is showing the undefined ....