This is my check-box and it’s created dynamically by getting the value of the XUL tree.
var yyahoo = tree.view.getCellText(i, tree.columns.getNamedColumn("yahoo"));
var existing = document.getElementById('box');
var checkbox = document.createElement('checkbox');
capt.appendChild(checkbox);
checkbox.setAttribute('label', yyahoo);
checkbox.setAttribute("checked", "false")
checkbox.setAttribute('style', 'color: green;');
Like this I have dynamically created many check-boxes in my XUL file.
When I checked Mozilla website, it is explained that, i have to use hasAttribute() to get the value of the selected check-box, which is confusing to me.
Please help me to get the value of the selected check-box.
This is the button to get the values on-click.
<row><button label="get" oncommand="get();"/></row>
This is function: This function is not working ’cause something is missing in my function.
function get()
{
// check that the attribute exists before setting a value
var d = document.getElementById("box");
if (d.hasAttribute("checkbox")) {
alert(d);
}
}
Thanks for your support.
The
checkboxis a child of the element with IDbox, not an attribute. Try something like this:The
checkedproperty tells you whether the checkbox is currently selected or not.hasAttribute('checked')tells you whether the attribute was set or not. Maybe you have to use both, I don’t know.Apparently, thecheckbox[MDN] element has no attributevalue, so I don’t know which value you are talking about.