0

I am currently utilizing a third party web-based application that allows for UI script injection.

Within the page I am trying to inject my UI script into are a list of elements with associated checkboxes. The following are checkboxes generated by the webpage by the original developers, I cannot change these:

<input type="checkbox" value="1" class="selectionCheckbox" checked="checked" onclick="foo(this)"> // For True (Checked)
<input type="checkbox" value="1" class="selectionCheckbox" onclick="foo(this)"> // For False (Unchecked)

I am trying to load their values into my own UI Script's checkboxs after the document is ready. The nature of my script is basically to inject a X/Y Grid of combinations instead of a list.

I have tried:

function loadCheckOne(vobj, objValue) {
    var containerObj = document.getElementById(objValue);
    var row = containerObj.getElementsByClassName("checkbox");
    // row[0] === the above mentioned input element

    if (row[0].checked){
        vobj.setAttribute("checked", "true");
        console.log("Marked.");
    }
    console.log(row[0].checked); // Prints: "undefined"
}

function loadCheckTwo(vobj, objValue) {
    var containerObj = document.getElementById(objValue);
    var row = containerObj.getElementsByClassName("checkbox");
    // row[0] === the above mentioned input element

    if (row[0].hasAttribute("checked")){
        vobj.setAttribute("checked", "true");
        console.log("Marked.");
    }
    console.log(row[0].hasAttribute("checked")); // Prints: "false"
}


function loadCheckThree(vobj, objValue) {
    var containerObj = document.getElementById(objValue);
    var row = containerObj.getElementsByClassName("checkbox");
    // row[0] === the above mentioned input element

    if (row[0].getAttribute("checked")){
        vobj.setAttribute("checked", "true");
        console.log("Marked.");
    }
    console.log(row[0].getAttribute("checked")); // Prints: "null"
}

The problem is all methods return false or null in some fashion, even for checkboxes that are checked at runtime of the script. Not sure where to go from here.

JSA
  • 134
  • 9
  • @KingReload I'm not sure if it is a duplicate just because none of the standard ways for checking if a checkbox is checked seem to be working for my case. But I'll scrub through the thread incase I catch a new idea. – JSA May 01 '17 at 15:15
  • first use `onclick="foo(this.value)"` second, you're missing the `foo(value)` function. – King Reload May 01 '17 at 15:18
  • You need to check `checked` property. You don't have checkboxed with class `checkbox`. – dfsq May 01 '17 at 15:20

0 Answers0