Asp.net js three-level linkage menu implementation method (1/3)

Source: Internet
Author: User

Asp tutorial. net js three-level linkage menu implementation method

Available in ie5.5, ie8, firefox 2.0.0.12, chrome 8.0.552.237
In ashx, obtain the corresponding value from the database tutorial through the input parameters.

Parameter name:

Type: The value is regiontwo (indicating that the second-level region is obtained) or regionthree (indicating that the third-level region is obtained ),

Oneid, indicating the first-level region number,

Twoid, indicating the second-level region number

Getregiontwoinfo and getregionthreeinfo are the methods for obtaining the IDs and names of level 2 and Level 3 regions.
Public void processrequest (httpcontext context)
{
String type = context. request. querystring ["type"];
If (type. equals ("regiontwo "))
    {
String oneid = context. request. querystring ["oneid"];
Context. response. contenttype = "text/plain ";
Context. response. write (getregiontwoinfo (oneid ));
    }
Else if (type. equals ("regionthree "))
    {
String oneid = context. request. querystring ["oneid"];
String twoid = context. request. querystring ["twoid"];
Context. response. contenttype = "text/plain ";
Context. response. write (getregionthreeinfo (oneid, twoid ));
    }
}
Js code

Create an xmlhttprequest object, send a request, and set the onreadystatechange function.

Var http_request = false;
Function send_request (url, content, callback)
{
If (window. xmlhttprequest)
  {
Http_request = new xmlhttprequest ();
If (http_request.overridemimetype)
    {
Http_request.overridemimetype ("text/xml ");
    }
  }
Else
  {
Try
    {
Http_request = new activexobject ("msxml2.xmlhttp ");
    }
Catch (e)
    {
Try
      {
Http_request = new activexobject ("microsoft. xmlhttp ");
      }
Catch (e)
      {
      }
    }
  }
   
If (! Http_request)
  {
Window. alert ("You cannot create an xmlhttprequest object instance. ");
Return false;
  }
 
If (navigator. useragent. indexof ("firefox") <0)
Http_request.onreadystatechange = callback;
Http_request.open ("get", url, false );
Http_request.setrequestheader ("content-type", "text/xml ");
Http_request.send (content );
   
If (navigator. useragent. indexof ("firefox")> = 0)
  {
If (callback = 1)
Http_request.onreadystatechange = populateclass1 ();
Else if (callback = 2)
Http_request.onreadystatechange = populateclass2 ();
  }
}
Initialize the drop-down box and call the send_request method. These two functions are called directly in the drop-down box.
Function getregiontwo (oneid)
{
If (oneid! = '0 ')
  {
Document. getelementbyid ("region_selregionthree"). options. length = 1;
Var url = "controls/getregionhandler. ashx? Type = regiontwo & oneid = "+ oneid;
   
If (navigator. useragent. indexof ("firefox") <0)
Send_request (url, null, populateclass1 );
Else
Send_request (url, null, 1 );
  }
Else
  {
Document. getelementbyid ("region_selregiontwo"). length = 1;
Document. getelementbyid ("region_selregiontwo"). selectedindex = 0;
Document. getelementbyid ("region_selregionthree"). length = 1;
Document. getelementbyid ("region_selregionthree"). selectedindex = 0;
  }
}

Function getregionthree (oneid, twoid)
{
If (oneid! = '0' & twoid! = '0 ')
  {
Var url = "controls/getregionhandler. ashx? Type = regionthree & oneid = "+ oneid +" & twoid = "+ twoid;
If (navigator. useragent. indexof ("firefox") <0)
Send_request (url, null, populateclass2 );
Else
Send_request (url, null, 2 );
  }
Else
  {
Document. getelementbyid ("region_selregionthree"). length = 1;
Document. getelementbyid ("region_selregiontwo"). selectedindex = 0;
  }
}

Homepage 1 2 3 Last page
Related Article

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.