


PHP implements three-level cascading drop-down box, multi-select drop-down box, drop-down box plug-in, drop-down box code
This is the information I found on the Internet about implementing three-level cascading drop-down boxes in PHP. I would like to share it with you so that everyone can make progress together. The specific content is as follows
index.php:
<html> <head> <meta http-equiv="Content-Type" c type="text/javascript" src="aa.js"></script> </head> <body> <form> <label> <select name="sel" . mysql_error()); if($result) while ($arr = mysql_fetch_array($result)){ echo <<<EOD <option value={$arr["id"]}>{$arr["name"]}</option> EOD; } mysql_close($conn); ?> </select> </label> <label> <select name="sel2" > <option>三级分类</option> </select> </label> </form> <input type=button value="send value" ><pre class="brush:php;toolbar:false"><!-- var xmlHttp var xmlHttp2 //函数showMenu(str) - 功能函数1 function showMenu(str) xmlHttp=GetXmlHttpObject() //调用GetXmlHttpObject()函数,创建XMLHttpRequest对象 if (xmlHttp==null) //如果创建失败,则 alert ("Browser does not support HTTP Request") return var url="get2.php" //定义url , 其主要读取数据库 url=url+"?q="+str url=url+"&sid="+Math.random() //Math对象的random方法,取随机数 xmlHttp. //设置当XMLHttpRequest对象xmlHttp状态改变时调用的函数,注意函数名后不要添加小括号 xmlHttp.open("GET",url,true) //使用XMLHttpRequest对象的open()方法 , 创建HTTP请求 xmlHttp.send(null) //使用XMLHttpRequest对象的open()方法 , 发送HTTP请求 } //函数showMenu(str) - 功能函数1 function showMenu2(str) { xmlHttp2=GetXmlHttpObject() //调用GetXmlHttpObject()函数,创建XMLHttpRequest对象 if (xmlHttp2==null) //如果创建失败,则 alert ("Browser does not support HTTP Request") return var url="get2.php" //定义url , 其主要读取数据库 url=url+"?q2="+str url=url+"&sid="+Math.random() //Math对象的random方法,取随机数 xmlHttp2.2 //设置当XMLHttpRequest对象xmlHttp状态改变时调用的函数,注意函数名后不要添加小括号 xmlHttp2.open("GET",url,true) //使用XMLHttpRequest对象的open()方法 , 创建HTTP请求 xmlHttp2.send(null) //使用XMLHttpRequest对象的open()方法 , 发送HTTP请求 } //函数BuildSel() , 根据返回的的字串 , 重新构建新的下拉菜单控件Select - 功能函数2 function BuildSel(str,sel) //先清空原来的数据. sel.options.length=0; var arrstr = new Array(); arrstr = str.split(","); if(str.length>0) //循环 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; } //函数stateChanged() - 响应HTTP请求状态变化 function stateChanged() //判断XMLHttpRequest对象的readyState属性值是否为4,如果为4表示异步调用完成(注意:异步调用完成 不代表 异步调用成功) if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") //如果异步调用成功 --> XMLHttpRequest对象的status属性值为200 , html文件在本地运行,则xmlHttp.status的返回值为0,故应该加上xmlHttp.status==0 if(xmlHttp.status==200 || xmlHttp.status==0) //调用文档对象模型DOM的getElementById()方法查找html文件中的标签txtHint , //innerHTML为IE浏览器中的属性,可以用来更改标签间文本的内容 , //xmlHttp.responseText , 通过XMLHttpRequest的responseText属性来获取数据 responseText,结果为字符串;responseXML,结果为XML形式 // document.getElementByIdx_x_xx_x_xx("txtHint").innerHTML=xmlHttp.responseText BuildSel(xmlHttp.responseText,document.getElementsByTagName_r("*").sel2) showMenu2(document.getElementsByTagName_r("*").sel2.value); } } //函数stateChanged() - 响应HTTP请求状态变化 function stateChanged2() //判断XMLHttpRequest对象的readyState属性值是否为4,如果为4表示异步调用完成(注意:异步调用完成 不代表 异步调用成功) if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") //如果异步调用成功 --> XMLHttpRequest对象的status属性值为200 , html文件在本地运行,则xmlHttp.status的返回值为0,故应该加上xmlHttp.status==0 if(xmlHttp2.status==200 || xmlHttp2.status==0) //调用文档对象模型DOM的getElementById()方法查找html文件中的标签txtHint , //innerHTML为IE浏览器中的属性,可以用来更改标签间文本的内容 , //xmlHttp.responseText , 通过XMLHttpRequest的responseText属性来获取数据 responseText,结果为字符串;responseXML,结果为XML形式 // document.getElementByIdx_x_xx_x_xx("txtHint").innerHTML=xmlHttp.responseText BuildSel(xmlHttp2.responseText,document.getElementsByTagName_r("*").sel3) } } //函数GetXmlHttpObject() - 创建XMLHttpRequest对象,即创建一个异步调用对象 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'"); //如果传递过来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); } //如果传递过来q2 if($_GET["q2"]){ $str = "SELECT * FROM fitment_sort WHERE supid= '".$_GET["q2"]."'"; //echo $str; $result = mysql_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); ?>
The above is the relevant code for implementing three-level cascading drop-down boxes in PHP. I hope it will be helpful for everyone to learn PHP programming.
The above introduces the implementation of three-level cascading drop-down boxes in PHP, including the contents of PHP and drop-down boxes. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
