javascript+php Application One: Web _php Tutorials

Source: Internet
Author: User
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 ...

  • Related Article

    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.