mardi 31 janvier 2017

How to get Text and Value of CheckBox with several way?

I already read the other article but still not solve it. I have check box that generate by :

$('#sel_div').append("<div style='margin-bottom:4px;margin-right:5px;float:left;width:80px;'><input type='checkbox' name=loc["+loc_id+"][] style='margin:2px;' value='"+myvalue+"' onClick='handler(this)'>"+description+"</div>");

The question is , how to get value of checkbox (myvalue) and text of checkbox (description) ?

What i have to do :

function handler(checkbox){
        var checkedValue = checkbox.value;
        alert(checkedValue);
        alert($('input[type=checkbox]:checked').next().val());
        alert($('input[type=checkbox]:checked').next().text());
}

The result :

checkedValue get correct value but the other alert shown blank.

Can anyone explain what wrong with the code ?

Thank you




Aucun commentaire:

Enregistrer un commentaire