A second-level linkage menu made by Ajax

Source: Internet
Author: User

In ie, the Select drop-down list box cannot be rendered using innerhtml .. Therefore, oselect cannot be used. innerhtml = <option> text </option>

<MCE: Script Type = "text/JavaScript"> <! -- <Br/> var XMLHTTP; <br/> function createxmlhttprequest () <br/>{< br/> If (window. XMLHttpRequest) <br/>{< br/> XMLHTTP = new XMLHttpRequest (); </P> <p >}< br/> else if (window. activexobject) <br/>{< br/> XMLHTTP = new activexobject ("micorosoft. XMLHTTP "); <br/>}< br/> else <br/> {<br/> alert (" XMLHTTP is not exist! "); <Br/>}< br/> var op = document. getelementbyid ("Province"); <br/> // var pid = op. options [op. selectedindex]. value; <br/> for (VAR I = 0; I <op. options. length; I ++) <br/>{< br/> If (op. options [I]. selected) <br/>{< br/> var pid = op. options [I]. value; <br/>}< br/> var url = "handler. ashx "// post submit <br/> // var url =" handler. ashx? PID = "+ PID // get submit XMLHTTP. open ("Post", URL, true) <br/> XMLHTTP. onreadystatechange = function () <br/>{< br/> If (XMLHTTP. readystate = 4) <br/>{< br/> If (XMLHTTP. status = 200) <br/>{< br/> call_back (XMLHTTP. responsetext); <br/>}< br/> XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded"); // post submit <br/> XMLHTTP. send ("pid =" + PID); // post submit <br/> // XMLHTTP. send (null); // get submit <br/>}< br/> function call_back (SS) <br/>{< br/> var citys = document. getelementbyid ("Di"); <br/> Di. innerhtml = ""; <br/> // For (VAR I = Citys. options. length-1; I> = 0; I --) <br/> // {<br/> // Citys. remove (I); <br/>/}< br/> // Citys. innerhtml = "<option> DF </option>" // This method does not work. In IE, select cannot be used for innerhtml rendering. <br/> Di. innerhtml = "<SELECT>" + SS + "</SELECT>"; <br/>}</P> <p> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body onload = "createxmlhttprequest () "> <br/> <select name =" Province "id =" Province "style =" width: 100px; "onchange =" createxmlhttprequest () "> <br/> <option value =" 1 "> Hubei </option> <br/> <option value =" 2 "> Hunan </option> <br/> <option value = "3"> Guangdong </option> <br/> </SELECT> <br/> <Div id = "Di"> <br/> <select name = "city" id = "city" style = "width: 100px; "> <br/> </SELECT> <br/> </div> <br/> </body>

The code for the corresponding page of handler. ashx server is as follows:Public class handler: ihttphandler {</P> <p> string conn = webconfigurationmanager. connectionstrings ["con"]. connectionstring; <br/> Public void processrequest (httpcontext context) {<br/> // string pid = context. request. querystring ["PID"]; // submit <br/> string pid = context. request. form ["PID"]; // post submit <br/> sqlconnection con = new sqlconnection (conn); <br/> con. open (); <br/> string SQL = "select cname from city where pid =" + PID; <br/> sqlcommand cmd = new sqlcommand (SQL, con ); <br/> sqldatareader SDR = cmd. executereader (); <br/> string output = ""; <br/> while (SDR. read () <br/>{< br/> output + = "<option>" + SDR [0]. tostring () + "</option>"; <br/>}< br/> context. response. write (output ); </P> <p >}< br/> Public bool isreusable <br/>{< br/> Get <br/>{< br/> return false; <br/>}</P> <p>}

 

The main problem encountered here is that select cannot be rendered using innerhtml in IE... A Div can be used to solve the problem.

 

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.