ajax - Jquery checkbox not getting checked -
i have function called 'getdata' contains ajax call returns data ( dynamically created list of fruits) via json. have function called 'addfruit' should check checkbox when user clicks button enters text value textbox , value not match 1 of values contained in json data.
for example if data returned ajax call {'orange', 'apple', 'pear'} , user clicks button adds 'banana' textbox, checkbox should checked.
below i've tried far:
function addfruit(data) { var fruit = $("#fruit").val(); //the value of input text box gets populated when user clicks '#buttonadd' button. $("#buttonadd").click(function() { $.each(data, function (item) { if ($('fruit:contains(" + data[item] + ")')) { $("#oldform").prop ("checked", false); } else { $("#oldform").prop ("checked", true); } }); }); } getdata().done(addfruit); // when ajax call completed, run addfruit function.
you forgot ;
after calling prop()
.
Comments
Post a Comment