Create a checkbox style drop-down list

Source: Internet
Author: User

 

/*
Checkbox style multi-select picklist
Author: Jim Wang @ January 2009
Http://jianwang.blogspot.com
Http://mscrm.cn
*/

//Pl-The picklist attribute; PLV-used to save selected picklist values
VaRPL=Crmform. All. new_picklist;
VaRPLV=Crmform. All. new_picklistvalue;

If (PL ! =   Null   && PLV ! =   Null )
{
Pl. style. Display =   " None " ;
PLV. style. Display =   " None " ;

// Create a div container
VaR Adddiv = Document. createelement ( " <Div style = 'overflow-Y: auto; Height: 80px; Border: 1px # 6699cc solid; Background-color: # ffffff; '/> " );
Pl. parentnode. appendchild (adddiv );

// Initialise checkbox controls
For ( VaR I =   1 ; I < Pl. Options. length; I ++ )
{
VaR Poption = Pl. Options [I];
If ( ! Ischecked (poption. Text ))
VaR Addinput = Document. createelement ( " <Input type = 'checkbox' style = 'border: none; width: 25px; align: Left; '/> " );
Else
VaR Addinput = Document. createelement ( " <Input type = 'checkbox' checked = 'checked' style = 'border: none; width: 25px; align: Left; '/> " );

VaR Addlabel = Document. createelement ( " <Label/> " );
Addlabel. innertext = Poption. text;

VaR Addbr = Document. createelement ( " <Br/> " );

Pl. nextsibling. appendchild (addinput );
Pl. nextsibling. appendchild (addlabel );
Pl. nextsibling. appendchild (addbr );
}

// Check if it is selected
Function Ischecked (ptext)
{
If (PLV. Value ! =   "" )
{
VaR Plvt = PLV. value. Split ( " | " );
For ( VaR I =   0 ; I < Plvt. length; I ++ )
{
If (Plvt [I] = Ptext)
Return   True ;
}
}
Return   False ;
}

// Save the selected text, this filed can also be used in Advanced Find
Crmform. attachevent ( " Onsave " , Onsave );
Function Onsave ()
{
PLV. Value =   "" ;
VaR Getinput = Pl. nextsibling. getelementsbytagname ( " Input " );

For ( VaR I =   0 ; I < Getinput. length; I ++ )
{
If (Getinput [I]. Checked)
{
PLV. Value + = Getinput [I]. nextsibling. innertext +   " | " ;
}
}
}
}

The style of the DIV must specify 'overflow-Y: auto ;'

Reference: http://www.cnblogs.com/MSCRM/articles/1377386.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.