How to get value only visible and checked from checkbox via javascript ?
https://jsfiddle.net/ytbvd6px/1/
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>
you can add cboxes[i].style.display != 'none'
in your if
condition like below
if (cboxes[i].checked != false && cboxes[i].style.display != 'none')
Demo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.