I want to know the number of checboxes checked in javascript. If only one checkbox is checked then it should show an alert message, otherwise it should do the processing. I tried if(names[i].checked>2) but it is not working.. Please help.
function insert_slide(ed, height, width)
{ var img=new Array();
var names=document.getElementsByName('image_id');
for(i=0;i<names.length;i++)
{
if(names[i].checked)
{
img[i] = "<IMG SRC='" + names[i].value + "'";
if(height != '') {
img[i] += " height='" + height + "'";
}
if(width != '') {
img[i] += " width='" + width + "'";
}
img[i] += " style='margin: 5px;' >";
editor.nicCommand("insertHTML", img[i]);
}}
hide_lightwindow();
}
A solution could be the following:
Get the
lenghtof all chechboxes in aform. Then check with aforloop, if there arecheckedchechboxes, for each one it finds adds1in the variablesumDemo: http://jsbin.com/ezafal/2