I’ve been given two arrays, each of which has several objects within them. I’m trying to make it so that when a certain dropdown selection is made, it pushes that “flight information” into a “flight summary” div, but I’m having a hard time figuring out how to do it.
var possibleDepartureFlights=[{year:2012,month:11,day:13,hour:17,minute:37,price:137.38} and so on];
var possibleReturnFlights=[{year:2012,month:11,day:18,hour:21,minute:45,price:189.46} and so on];
Each var has 10 objects within the array, each of which has all those properties.
And as a bonus question, I’ve figured out how to hide a “submit” button when the return flight selected is earlier than the departure, but I can’t figure out how to make the submit button come back when a different selection is made!
function displayDivs() {
var departureValue = $('#departureFlightsControl').val();
var returnValue = $('#returnFlightsControl').val();
if (departureValue != "default") {
$('.CumulativeSummary').addClass('totalAvailable');
$('.DepartureSummary').addClass('flightChosen');
}
if (returnValue != "default") {
$('.CumulativeSummary').addClass('totalAvailable');
$('.ReturnSummary').addClass('flightChosen');
}
if ($('#returnFlightsControl').val() < $('#departureFlightsControl').val()) {
$('.SubmitArea').hide();
}
Sorry if this question is vague! I’m new to jQuery and JavaScript, so I’m not really sure what I’m doing (and I’m not even really sure what to Google for to find the answer to my problem(s)). Please use small words, as if you’re speaking to a child. Thanks!
Your question is really too broad, anyways… Suppose you have following
The
possibleDepartureFlightsis an array of two objects and the first element of the array is the first object and it’s{year:2012,month:10,day:13,hour:10,minute:37,price:137.38}and it’s index is0and the second element in yourpossibleDepartureFlightsarray is the second object and it’s{year:2012,month:11,day:15,hour:17,minute:47,price:150.50}and it’s index is1. Now, if you want to access themonthproperty of the first item of the array then you can write likeFor the
monthof the second item/object in the array you can writeTo loop through the
arrayand print out the each property of every objects, you can try thisAn Example Here.
Remember, this is only a short example and there are more about arrays and objects in
JavaScript. Also remember that you canloopan object with for in like for loop. Also this one could be helpful too.