Empty "name" for checkboxes

Hi Guys,

I wrote a script which counts the checked check-boxes in a custom DocType:

frappe.ui.form.on(“SOR”, {
validate: function checkboxes()
{
var inputElems = document.getElementsByTagName(“input”),
count = 0;
for (var i=0; i<inputElems.length; i++) {
if (inputElems[i].type == “checkbox” && inputElems[i].checked == true){
count++;
alert(inputElems[i].name);
}
}
alert(count);
}
})

Although the Name of the checkbox is filled in the script returns empty result:

Any idea why is this happening?

Regards!

I guess you don’t put two alerts one after the other!

Better way of debugging is using console.log and check in your JS console.

SOLVED

frappe.ui.form.on(“SOR”, {
validate: function(frm) {
“use strict”;
var count_yes = 0;
var count_no = 0;
$(“form”).each(function(){
var a = $(this).find(“:input[type=‘checkbox’][data-fieldtype=‘Check’]”);
var vProps = a.get(0);
var name = a.attr(“data-fieldname”);
var isOnOff;
if( typeof vProps !== ‘undefined’ && (name.indexOf(“yes_”) == 0)) {
isOnOff= vProps.checked;
if (isOnOff) count_yes++;
}
if( typeof vProps !== ‘undefined’ && (name.indexOf(“no_”) == 0)) {
isOnOff= vProps.checked;
if (isOnOff) count_no++;
}
});
alert(count_yes + “,” + count_no);
}
});

That’s what frieds are for :slight_smile: