SoFunction
Updated on 2025-04-14

Implementing CHECKBOX control with htc


/*
Description: CHECKBOX control
Version:            1.1
Note: The text that follows behind the CHECKBOX control
It is used to obtain the htc_myLabel of the CHECKBOX object to display it
Updated and added the indeter attribute to increase uncertain choices
*/
<public:component>
<public:attach event="oncontentready" onevent="fnInit()" />
<public:attach event="onpropertychange" onevent="fnPropertychange()" />
<script language="Javascript">
var checkBoxImg=("IMG");
ImageArray=[];
ImageArray["checkbox_false"]="checkbox_false.gif";
ImageArray["checkbox_false_down"]="checkbox_false_down.gif";
ImageArray["checkbox_false_over"]="checkbox_false_over.gif";
ImageArray["checkbox_true"]="checkbox_true.gif";
ImageArray["checkbox_true_down"]="checkbox_true_down.gif";
ImageArray["checkbox_true_over"]="checkbox_true_over.gif";
ImageArray["checkbox_indeter"]="checkbox_indeter.gif";
ImageArray["checkbox_indeter_down"]="checkbox_indeter_down.gif";
ImageArray["checkbox_indeter_over"]="checkbox_indeter_over.gif";
function preLoad(path,obj){
    for(i in obj){
        this[i]=new Image();
        this[i].src=path+obj[i];
        }
    return this;
    }
preb=new preLoad("images/",ImageArray);
function fnInit(){
    var o=element;
    if(=="checkbox"){
        var _table=("TABLE");
        _table.cellSpacing="0px";
        _table.cellPadding="0px";
        _table.border="0px";
        if(){
            _table.="alpha(Opacity=50)";
            }
        else{
            _table.="";
            }
        _table.="inline";
        var _tr=_table.insertRow();
        var _td=_tr.insertCell();
        if (){
            =preb["checkbox_true"].src;
            }
        else{
            =preb["checkbox_false"].src;
            }
        if(=="true"){
            ="true";
            =preb["checkbox_indeter"].src;
            }
        _td.appendChild(checkBoxImg);
        _td=_tr.insertCell();
        _td.="bottom";
        if(o.htc_myLabel){
            _td.innerHTML="&nbsp<label style='cursor: hand'>"+o.htc_myLabel+"</label>";
            }
        ("afterEnd",_table);
        ="none";
        _table.attachEvent("onmouseover",function(){Baction("over")});
        _table.attachEvent("onmouseout",function(){Baction("out")});
        _table.attachEvent("onmousedown",function(){Baction("down")});
        _table.attachEvent("onmouseup",function(){Baction("up")});
        _table.attachEvent("onclick",function(){fnClick()});
        }
    }
function fnPropertychange(){
    var o=element;
    switch(().toLowerCase()){
        case "checked":
            Baction("up");
            break;
        }
    }
function fnClick(){
    var o=element;
    if(=="checkbox"){
        if()return;
        if(){
            =preb["checkbox_false"].src;
            }
        else{
            =preb["checkbox_true"].src;
            }

        =!;
        }
    }
function Baction(action){
    var o=element;
    if(=="checkbox"){
        if()return;
        if(action=="up"||action=="over"){
            if(){
                =preb["checkbox_indeter_over"].src;
                }
            else if(){
                =preb["checkbox_true_over"].src;
                }
            else{
                =preb["checkbox_false_over"].src;
                }
            }
        if(action=="out"){
            if(){
                =preb["checkbox_indeter"].src;
                }
            else if(){
                =preb["checkbox_true"].src;
                }
            else{
                =preb["checkbox_false"].src;
                }

            }
        if(action=="down"){
            if(){
                =preb["checkbox_indeter_down"].src;
                }
            else if(){
                =preb["checkbox_true_down"].src;
                }
            else{
                =preb["checkbox_false_down"].src;
                }
            =false;
            }
        }
    }
</script>
</public:component>