views:

58

answers:

2

How to get the checkbox names when that form is loaded by html template. in Java Script?

+1  A: 

if you know jquery its easy use

$(document).ready(function() {

            $('input:checkbox').each(function() 
            { 
             do ....   
            }); 

    });

if you use only js, run over elements and check if element.type == 'checkbox'

Haim Evgi
+1  A: 
var inputs = document.getElementsByTagName('input');
var names = [];
for(var i = 0; i < inputs.length; i++){
    if(inputs[i].type == 'checkbox') names.push(inputs[i].name);
}

Will give you all their names in an array if you're not using jQuery. You can dump that push() call and do whatever you need to there if you just want to operate on checkboxes.

Just remember, if you have a ton of inputs on your page this will be a slow operation.

ajm