开发者

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(Def开发者_如何转开发CharLabel);
        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;

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜