mercredi 4 mai 2016

How to get value only visible and checked from checkbox via javascript?

How to get value only visible and checked from checkbox via javascript ?

http://ift.tt/1rnsTI9

from html code. It's have 3 checked checkbox and 1 diaplay : none on checkbox value = 3

when press button, I want to get value only visible and checked checkbox. in this case i want to alert 1-4-

How can i do ?

<script>
function test_fn(){
    var cboxes = document.getElementsByName('test_name[]');
    var len = cboxes.length;
    var pack_value = '';
    for (var i=0; i<len; i++) {
        if(cboxes[i].checked != false)
        {
            pack_value += cboxes[i].value+"-";
        }
    }

    alert(pack_value);    
}
</script>




Aucun commentaire:

Enregistrer un commentaire