javascript+php Application One: The dynamic realization of double drop-down menu in Web page making
---excerpted from the Internet
In the Web page production, often encountered this situation, through the main drop-down menu selection, the dynamic generation of sub-drop-down menu. For example: In the main menu has "Focus News", "lifestyle", "Mood Story" three options, through the "Focus News" selection, sub-menu automatically generated such as "domestic", "international", "Sports", "entertainment", and so on.
With JavaScript, we can easily achieve these effects. The problem is that if the options in the menu are extracted dynamically from a database (or other file), it's not easy to implement. Based on my own practical experience, the author introduces a method of using JavaScript + PHP, and the database in this paper uses MySQL. In this example, I will also describe how to return the selection state of the last menu option after each form submission.
The role of PHP as described in this article is to extract menu options from the database, and another function is to generate JavaScript code. Readers can use their own familiar interpretive language, such as ASP.
To simplify the code, I assume that the main menu has been constructed from HTML, because the submenu needs to be dynamically designed, so only the basic framework is drawn, the HTML code is as follows:
Main Menu DesignSpotlight NewsLife styleMood story//value must match the menu array below
Sub-menu Design
What we need to consider is what steps the onchange () event of the menu needs to complete. The general process is to construct a submenu item based on the options in the main menu. The Sub-menu item text is best set beforehand. Based on this idea, the author uses the combined Array Record submenu option in JavaScript and is generated automatically by PHP at load time. Thus, the author has designed the following JavaScript function SetMenu ():
function SetMenu () {
Menu=array ("A", "B", "C"); Constructing a menu Union array
$db = new my_db ();
$db->database = "* * *"; Constructs a new MySQL connection, where phplib is used
$mmenu = Array ("A", "B", "C"); Here the author makes a simplification
for ($i =0; $i
$id = $mmenu [$i];
$db->query ("Select Menu from class where MenuID = '". $id. "");
http://www.bkjia.com/PHPjc/629500.html www.bkjia.com true http://www.bkjia.com/PHPjc/629500.html techarticle javascript+php Application: The dynamic realization of double drop-down menu in Web page making---from the Internet in the production of web pages, often encountered this situation, through the main drop-down menu selection, dynamic ...