Reputation: 17
After receiving "day" from a text input, how can I display the <product>
of the <availabilities>
, ONLY from the same date using jQuery? Maybe with the use of .siblings()
?
<?xml version='1.0' encoding='iso-8859-15'?>
<timetable>
<date>
<day>22-01-2013</day>
<availabilities>
<availability>
<starttime>10:00</starttime>
<endtime>13:00</endtime>
<startplace>Funchal</startplace>
<endplace>Funchal</endplace>
<resource>Excursões na Madeira</resource>
<idstartplace>18</idstartplace>
<idendplace>18</idendplace>
<idperiodoconsumo>13289</idperiodoconsumo>
<idproduct>23</idproduct>
<product>EXC_SANT</product>
<idtimeperiod>11523</idtimeperiod>
<idavailability>3561</idavailability>
</availability>
<availability>
<starttime>10:00</starttime>
<endtime>13:00</endtime>
<startplace>Funchal</startplace>
<endplace>Funchal</endplace>
<resource>Excursões na Madeira</resource>
<idstartplace>18</idstartplace>
<idendplace>18</idendplace>
<idperiodoconsumo>13290</idperiodoconsumo>
<idproduct>33</idproduct>
<product>foot</product>
<idtimeperiod>11524</idtimeperiod>
<idavailability>3593</idavailability>
</availability>
<availability>
<starttime>10:00</starttime>
<endtime>13:00</endtime>
<startplace>Funchal</startplace>
<endplace>Funchal</endplace>
<resource>Excursões na Madeira</resource>
<idstartplace>18</idstartplace>
<idendplace>18</idendplace>
<idperiodoconsumo>13289</idperiodoconsumo>
<idproduct>22</idproduct>
<product>VLT_ILHA</product>
<idtimeperiod>11523</idtimeperiod>
<idavailability>3561</idavailability>
</availability>
</availabilities>
</date>
<date>
...
</date>
...
Here's my sucess: function:
function parseStuff(data){
$(data).find('date').each(function(){
var day = $(this).find('day').text();
if (day==decodeURI(iHash[3])){
alert('Date matches!');
}
});
}
I'd appreciate some help, I have no idea how to do this.. :|
Upvotes: 0
Views: 237
Reputation: 74738
Try this one:
var product = $(this).find('product').text();
i think you have to put this here:
if (day==decodeURI(iHash[3])){
var product = $(this).find('product').text();
alert('Date matches!');
}
Upvotes: 1
Reputation: 1754
This should work for you:
function parseStuff(data,toBeMatchedDate){
productList=array();
$(data).find('date').each(function(){
var day = $(this).find('day').text();
if (day==decodeURI(iHash[3]) && day==toBeMatchedDate) //if date is matched
{
xmlProdcutList=$(this).find('product'); //all the products associated with this date
$.each(function(i,thisProduct){
productList.push(thisProduct.text()); //store in the main array
});
return productList;
}
});
}
Upvotes: 0