Copy codeThe Code is as follows:
Function AddDropDownList (id, fatherCtl)
{
If (! Document. getElementById (id ))
{
Var ddl = document. createElement ('select ');
Ddl. setAttribute ("id", id );
If (fatherCtl & document. getElementById (fatherCtl ))
Document. getElementById (fatherCtl). appendChild (ddl );
Else
Document. body. appendChild (ddl );
}
}
// Delete the specified drop-down list
Function RemoveDropDownList (id)
{
Var ctl = document. getElementById (id );
If (ctl)
Ctl. parentNode. removeChild (ctl );
}
// Add options to the drop-down list
Function AddDDDLOption (id, text, value)
{
Var ctl = document. getElementById (id );
If (ctl)
{
Ctl. options [ctl. options. length] = new Option (text, value );
}
}
// Delete all options
Function RemoveAllDDLOptions (id)
{
Var ctl = document. getElementById (id );
If (ctl)
{
Ctl. options. length = 0;
}
}
// Delete the option of the specified index
Function RemoveDDLOption (id, index)
{
Var ctl = document. getElementById (id );
If (ctl & ctl. options [index])
{
Ctl. options [index] = null;
}
}
// Obtain the value selected from the drop-down list
Function GetDDLSelectedValue (id)
{
Var ctl = document. getElementById (id );
If (ctl)
{
Return ctl. options [ctl. selectedIndex]. value;
}
}
// Obtain the selected text from the drop-down list
Function GetDDLSelectedText (id)
{
Var ctl = document. getElementById (id );
If (ctl)
{
Return ctl. options [ctl. selectedIndex]. text;
}
}