Use PHP to implement real------linked Drop-down list

Source: Internet
Author: User
Tags array implement php database query
Dropdown | Drop-down list two files below copy to the same file, Access through the Web path index.html see, this is through the IFRAME to achieve the dynamic update, list.php current content is relatively simple, you see through the list.php database query, and then display the query results list.

Index.html
<body>
<form name= "Myfrm" >
<select name= "Mlist" >
<option value= "0" > Please select ...</option>
<option value= "Beijing" > Beijing </option>
<option value= "Tonghua" > Tonghua </option>
</select>
<select name= "Slist" >
</select>
<iframe id= "Frame" src= "list.php?city=" style= "Display:none"; ></iframe>
<script language= "JavaScript" >
function changes () {
Frame.location.href = "list.php?city=" + document.myfrm.mlist.value;
}
</script>
</form>
</body>


list.php

<?php
$data = Array ("Beijing" =>array ("Xiao Qiang", "Prosperous wealth", "Xiao Qiang his father"),
"Tonghua" =>array ("Xiao Wen", "Xiao Song", "their son");

$city = $_get["City"];

$result = $data [$city];

$str = "<script language=\" javascript\ ">list = parent.document.myfrm.slist;list.length = 0;";

if ($result ==null)
$str. = "TMP = new Option (\ ... \" \ "\"); list.options[0] = tmp; ";
Else
foreach ($result as $i => $value)
$str. = "TMP = new Option (\" {$value}\ ", \" {$value}\ "); list.options[$i] = tmp;";
$str. = "</script>";

Echo $str;
?>




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.