Php + ajax implement select classification level-2 menu effect

Source: Internet
Author: User
Tags php code

Html code

The code is as follows: Copy code

<Select id = "teId" name = "te_id" onchange = "getArea ()">
<Option value = "1000"> -- select a category -- </option>
<Option value = "1"> real estate knowledge </option>
<Option value = "8"> housing sales </option>
<Option value = "16"> Laws and regulations </option>
<Option value = "24"> Bank loan </option>
<Option value = "31"> Real Estate type </option>
<Option value = "40"> decoration Feng Shui </option>
<Option value = "47"> real estate brokerage </option>
<Option value = "52"> Other problems </option>
<Option value = "54"> Real Estate Q & A </option>
</Select>
<Span id = "teTid"> </span>
<Span> </span>
<Select id = "wealth" name = "wealth">
<Option value = ""> -- select reward points -- </option>
<Option value = "0"> 0 </option>
<Option value = "5"> I want to give 5 </option>
<Option value = "15"> I want to give 15 </option>
<Option value = "30"> 30 </option>
<Option value = "50"> 50 </option>
</Select>

Ajax code

The code is as follows: Copy code

// Create an ajax engine
Function getXmlHttpObject (){
Var xmlHttpRequest;

If (window. ActiveXObject ){

XmlHttpRequest = new ActiveXObject ("Microsoft. XMLHTTP ");
} Else {

XmlHttpRequest = new XMLHttpRequest ();
 }

Return xmlHttpRequest;
}

Var myXmlHttpRequest = "";

Function getArea (){
// Alert (ID ('teid'). value );
MyXmlHttpRequest = getXmlHttpObject ();
// Determine whether www.111cn.net can be used
If (myXmlHttpRequest ){
// Post sends data
Var url = "ajax_tiwen.php ";
Var date = "teId =" + ID ('teid'). value;

MyXmlHttpRequest. open ("post", url, true );
 
MyXmlHttpRequest. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded; charset = utf-8 ");
MyXmlHttpRequest. onreadystatechange = TiWen;
MyXmlHttpRequest. send (date );
 }
}

Php code

The code is as follows: Copy code
$ Str = '';
If (! $ TeamId)
{
 
$ Str. = '<select name = "te_tid"> ';
$ Str. = '<option value = "1000"> -- select a category -- </option> ';
$ Str. = '</select> ';
Echo $ str;
Exit;
}
Else
{
$ Str. = '<select id = "teTid" name = "te_tid"> ';
$ Str. = '<option value = "1000"> -- select a category -- </option> ';
Foreach ($ teamId as $ v)
 {
$ Str. = '<option value = "'. $ v ['id']. '">'. $ v ['tname']. '</option> ';
 }
$ Str. = '</select> ';
Echo $ str;
}

This site Original tutorial: Reprinted with the source of http://www.111cn.net otherwise at your own risk

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.