Two-level linkage dropdownlist implemented by xmlhttp

Source: Internet
Author: User

When registering a user, you need to filter out different products in the database based on different user types. Think about it. The best way to do this is to do nothing new.

Foreground steps: (js)

Function fillProduction ()
{
Var dwl = document. all ("DropdownlistLevel ");
Var htp = new ActiveXObject ("microsoft. xmlhttp ");
Var url = "reg. aspx? Fp = "+ dwl. value; htp. open (" POST ", url, false );
Htp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded") htp. send ();
Var str = htp. responseText;
If (str! = "")
{
Var mydata = str. split ("$ ");
If (mydata [0]! = 0)
{
For (var I = 1; I <= mydata [0]; I ++)
{
Var tmp = mydata [I]. split ("@");
Var item = new Option ();
Item. text = tmp [0] + "|" + tmp [1] + "BV"; item. value = tmp [2]; document. submit. dropDwonListProduction. options [I-1] = item;
}
Document. submit. hidpid. value = document. submit. DropDwonListProduction. value;
}
Else
{
Var len = document. submit. DropDwonListProduction. options. length;
For (var I = len-1; I> = 0; I --)
{
Document. submit. DropDwonListProduction. options. remove (I );
}
Document. submit. hidpid. value = "";
}
}
Htp = null;
}

Background code:

Private void fillProduction ()
{
String SQL;
SQL = "select pgr_prod_descr, pgr_bv_value, values from prod_grp t where t. pgr_bv_value = (select dal_bv from def_acct_level where dal_id =" + Request ["fp"] + ")";
DataTable dt;
Dt = SQLHelper. FillDataTable (SQLHelper. CONN_STRING, CommandType. Text, SQL );
String tmp;
If (dt. Rows. Count> 0)
{
Tmp = dt. Rows. Count. ToString () + "$ ";
For (int I = 0; I <= dt. Rows. Count-1; I ++)
{
Tmp = tmp + dt. rows [I] [0]. toString () + "@" + dt. rows [I] [1]. toString () + "@" + dt. rows [I] [2]. toString () + "$ ";
}
}
Else
{
Tmp = "0 $ ";
}
Response. Write (tmp );
}

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.