Implement a real-stay drop-down list with PHP

Source: Internet
Author: User
Tags implement php database

The following two files are 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" onchange="changes();">
<option value="0">请选择...</option>
<option value="北京">北京</option>
<option value="通化">通化</option>
</select>&nbsp;
<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.