PHP implementation of Level three Cascade dropdown box _php Tips

Source: Internet
Author: User
Tags learn php object model

This is what I found on the Internet PHP to achieve Level three Cascade dropdown box of information, share a everyone, we progress together, the specific content as follows

index.php:

 

Aa.js

<!--var xmlHttp var xmlHttp2//function ShowMenu (str)-Functional functions 1 function showmenu (str) xmlhttp=getxmlhttpobject ()//Call GETXM Lhttpobject () function, create XMLHttpRequest object if (xmlhttp==null)//If creation fails, alert ("Browser does not support HTTP Request") r Eturn var url= "get2.php"//define URL, its primary read database url=url+ "? q=" +str url=url+ "&sid=" +math.random ()//math object Random method , take the random number xmlhttp.onreadystatechange=statechanged//Set the function that is called when the XMLHttpRequest object XmlHttp state changes, note the function name do not add parentheses Xmlhttp.open (" Get ", url,true///Use the XMLHttpRequest object's open () method, create HTTP request xmlhttp.send (NULL)//Use the XMLHttpRequest object's open () method, send HTTP please Find}//function ShowMenu (str)-function 1 function showMenu2 (str) {xmlhttp2=getxmlhttpobject ()//Call Getxmlhttpobject () function, create XMLHTTPR         Equest object if (xmlhttp2==null)//If creation fails, alert ("Browser does not support HTTP Request") return to Var url= "get2.php" Defines the URL, which mainly reads the database url=url+ "? q2=" +str url=url+ "&sid=" +math.random ()//math The object's random method, taking random numbers xmlhttp2.onreadyst ATECHANGE=STATECHANGED2//Set when XMLHTtprequest Object XMLHTTP function called when state changes, note function name do not add parentheses xmlhttp2.open ("get", url,true)//Use the XMLHttpRequest object's open () method to create an HTTP request Xmlhttp2.send (NULL)//using the open () method of the XMLHttpRequest object, send the HTTP request}//function Buildsel (), and reconstruct the new Drop-down menu control Select-function letter, based on the returned string
  Number 2 function Buildsel (Str,sel)//Clear the original data first.   sel.options.length=0;   var arrstr = new Array ();
  Arrstr = Str.split (",");       if (str.length>0)//loop for (Var i=0;i<arrstr.length;i++) var subarrstr=new Array ();
      Subarrstr=arrstr[i].split ("|");     Sel.options.add (New Option (subarrstr[1],subarrstr[0)); Sel.options[0].selected=true; }//function statechanged ()-Response to HTTP request State change function statechanged ()///Determine whether the ReadyState property value of the XMLHttpRequest object is 4, if 4 is the asynchronous call complete (note: The asynchronous call completion does not represent the success of the asynchronous call) if (xmlhttp.readystate==4 | | xmlhttp.readystate== "complete")//if the asynchronous call succeeds--> XMLHttpRequest object has a value of Status property, HTML file is run locally, Xmlhttp.status return value is 0, so should add xmlhttp.status==0 if (xmlhttp.status==200 | | xmlhttp.status==0)//Call the getElementById () method of the Document Object model DOM to find the label in an HTML file txtHint,//innerhtml is a property in IE browser that can be used to change the contents of the text between labels,//xmlhttp.responsetext, to get data through XMLHttpRequest responsetext Properties resp Onsetext, the result is a string; Responsexml, the result is an XML form//Document.getelementbyidx_x_xx_x_xx ("Txthint"). innerhtml= Xmlhttp.responsetext Buildsel (Xmlhttp.responsetext,document.getelementsbytagname_r ("*"). Sel2) ShowMenu2 (document . Getelementsbytagname_r ("*"). Sel2.value); }//function statechanged ()-Response to HTTP request State change function stateChanged2 ()///Determine whether the ReadyState property value of the XMLHttpRequest object is 4, if 4 is the asynchronous call completion (note : The asynchronous call completion does not represent the success of the asynchronous call) if (xmlhttp2.readystate==4 | | xmlhttp2.readystate== "complete")//if the asynchronous call succeeds--> XMLHttpRequest object has a value of Status property, HTML file is run locally, Xmlhttp.status return value is 0, so should add xmlhttp.status==0 if (xmlhttp2.status==200 ||
     xmlhttp2.status==0)//Call the getElementById () method of the Document Object model DOM to find the label txthint in the HTML file,//innerhtml to the properties in IE Explorer, which can be used to change the contents of the text between labels. Xmlhttp.responsetext, XMLHttpRequest the ResponseText property to obtain the data responsetext, the result is a string; Responsexml, the result is XML form//Documen T.getelementbyidx_x_xx_x_xx ("TxthiNT "). Innerhtml=xmlhttp.responsetext Buildsel (Xmlhttp2.responsetext,document.getelementsbytagname_r (" * "). sel3)}}
function Getxmlhttpobject ()-Creates a XMLHttpRequest object that creates an asynchronous call object function Getxmlhttpobject () var xmlhttp=null; Try//Firefox, Opera 8.0+, Safari xmlhttp=new XMLHttpRequest (); catch (E)//internet Explorer try Xmlhttp=new activexobject ("msxml2.xmlhttp"); catch (E) xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP"); return xmlHttp; -->

Get2.php

<?php header (' content-type:text/html;charset=gb2312 ');
$conn = mysql_connect (' localhost ', ' root ', ') or die (' could not connect: '. Mysql_error ());
mysql_select_db (' fitment ', $conn) or Die (' can\ ' t use database: '. mysql_error ());
mysql_query ("Set names ' gb2312 '"); If passed over Q if ($_get["Q"]) {$strs = "select * from Fitment_sort WHERE supid= '". $_get["Q"]. "'
";
Echo $str; $results = mysql_query ($strs) or Die ("Invalid query:".
Mysql_error ()); if ($results) while ($arrs = Mysql_fetch_array ($results)) {$strings. = $arrs ["id"]. "|".   $arrs [' name ']. ', '; Echo substr ($strings, 0,strlen ($strings)-1); //If passed over Q2 if ($_get["Q2"]) {$str = "select * from Fitment_sort WHERE supid= '". $_get["Q2"].//echo $str; $result = m Ysql_query ($str) or Die ("Invalid query:".
Mysql_error ()); if ($result) while ($arr = Mysql_fetch_array ($result)) {$string. = $arr ["id"]. "|".   $arr [' name ']. ', '; Echo substr ($string, 0,strlen ($string)-1); } mysql_close ($conn);?>

Above is the PHP implementation of level three Cascade Drop-down box of related code, I hope to learn PHP program design help.

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.