vendredi 31 juillet 2015

How to get value of each checkbox placed in list

List is dynamically placed inside this div:

  <div id="SymptomSection"></div>

List is built here:

 function listSymptoms(pObject) {
    var r = new Array();
    var j = -1;
    var after_i = -1;
    var name;
    r[++j] = '<ul class="list-group" id="no-dot-list">';
    for (var i in array) {
        var d = array[i];
        if (d.FettleType == pObject.value) {
            after_i++;
            name = d.Type.toString();
            r[++j] = '<li class=" my-symptom-list">'
            r[++j] = '<input name="SymptomList['
            r[++j] = after_i
            r[++j] = '].IsChecked" id="fettleControl" type="checkbox" value="false"'
            if (d.IsChecked&& firstLoadOnPage)
            r[++j] = ' checked '
            r[++j] = '>'
            r[++j] = d.DisplayName
            r[++j] = '</input>'
            r[++j] = '<input name="SymptomList['
            r[++j] = after_i
            r[++j] = '].IsChecked" type="hidden" value="false">'
            r[++j] = '</li>';
        }
    }
    r[++j] = '</ul>';
    //for(var b in r)
    //{ alert(r[b]);}
    firstLoadOnPage = false;
    var list = document.getElementById('SymptomSection');
    list.innerHTML = r.join('');
};

Function code:

function validateFettleSymptoms() {
var after_i = 0;
$("#SymptomSection li").each(function () {
    var isChecked = $(this).find('#fettleControl'+after_i).first().attr("checked");
    alert($(this).find('#fettleControl' + after_i).first().val);
    if (isChecked)
        return true;
    after_i++;
});
return false;
}

Problem is How do I correctly get the checked value? I've tried many options (with finding through id, classname, etc) and it did not work, alert was saying "undefined". Now it says a huge portion of code

I can't post pictures, so here's a link for screenshot of an alert http://ift.tt/1OF7NL8




Aucun commentaire:

Enregistrer un commentaire