mardi 31 mars 2015

jquery search textbox if there is a textbox for every checkbox selector

In my project I have a list of ingredients for cooking listed in a checkbox list i have a fixed list and i also give an option to add others if not listed. I have a checkbox with input box next to if for the purpose of adding new ingredients if it is not on the list. I want to add a flag for each input boxc that appears in every checkbox so that when i search the database i know how many textbox i need to generate


So my problem is how to get the textbox if it is available for every checkbox my code is below



$.each($("input[name='ingredients[]']:checked"), function() {
var othersflag = 0;
if ($(this).parent().parent().find("input[type='text']")) {
console.log($(this).parent().parent().find("input[type='text']").val());
othersflag = "1";
} else {
othersflag = "0";
}
Ingredients.push({
ingredients: $(this).parent().find('span').text() || $(this).parent().parent().find('.othersingredientstext').val(),
othersflag: othersflag
});
console.log(Ingredients);
});




Aucun commentaire:

Enregistrer un commentaire