简体   繁体   中英

Accessing dynamically created Dojo checkbox widgets in javascript

I am trying to create checkboxes using Dojo problematically. The no. of checkboxes are different according to the selection made.

I am able to create the boxes. The problem is when I try to submit the form and try to access the boxed using dijit.byid("ID"), the IE gives undefined message.

below is the code. I am abe to creae the checkboxes but cant access them.

Code to create checkboxes in Javascript :

function displayDefiningC(definingCharacteristicCount,fieldData){

try{

if( (document.getElementById("problemDefChar").style.display == "none") && (definingCharacteristicCount > 0))
{
    document.getElementById("problemDefChar").style.display = "block";

    **var DefCharSpan = dojo.doc.createElement("span");


    for(j = 1; j<=definingCharacteristicCount; j++ )
    {
        var DefCharCheckbox = new dijit.form.CheckBox();
        DefCharCheckbox.id = "PDCDEFCHAR"+j;
        DefCharCheckbox.name = "PDCDEFCHAR"+j;
        DefCharCheckbox.value = fieldData[j].DefiningCharacter;
        DefCharCheckbox.checked = false;
        var DefCharLabel = dojo.doc.createElement("span");
        DefCharLabel.innerHTML = fieldData[j].DefiningCharacter;
        var DefCharBreak = dojo.doc.createElement("br");
        DefCharSpan.appendChild(DefCharCheckbox.domNode);
        DefCharSpan.appendChild(DefCharLabel);
        DefCharSpan.appendChild(DefCharBreak);
        dojo.place(DefCharSpan, dojo.byId("DefCharCheckBox"), "last");

    }**

}
}catch(e){
alert(e);    

}

return;

}

and i am trying to access these checkboxes using :

var defchar= dijit.byId("PDCDEFCHAR1");
alert("defchar " +defchar);

but this given undefined.

I have got it solved....the problem was I was creating it wrongly :)

function displayDefiningC(definingCharacteristicCount,fieldData){

try{

if( (document.getElementById("problemDefChar").style.display == "none") && (definingCharacteristicCount > 0))
{
    document.getElementById("problemDefChar").style.display = "block";

    var DefCharSpan = dojo.doc.createElement("span");


    for(j = 1; j<=definingCharacteristicCount; j++ )
    {


        var DefCharCheckbox = new dijit.form.CheckBox({
            name: "PDCDEFCHAR"+j,
            id: "PDCDEFCHAR"+j,
            value: fieldData[j].DefiningCharacter,
            checked: false,
     });

        var DefCharLabel = dojo.doc.createElement("span");
        DefCharLabel.innerHTML = fieldData[j].DefiningCharacter;
        var DefCharBreak = dojo.doc.createElement("br");
        DefCharSpan.appendChild(DefCharCheckbox.domNode);
        DefCharSpan.appendChild(DefCharLabel);
        DefCharSpan.appendChild(DefCharBreak);
        dojo.place(DefCharSpan, dojo.byId("DefCharCheckBox"), "last");

    }

}
}catch(e){
alert(e);    

}

return;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM