如何制作一个下拉列表链接另一个在PHP?

时间:2014-03-18 05:43:03

标签: php

这是我的要求:

当我从 STATE 下拉列表中选择一个分区时,我希望该状态下的分区列在下一个DISTRICT下拉列表中。

我该怎么做?

这是我的代码:

请整理出来。

<?php
//echo "welcome";
include("flash.html");
?>
<html>
<head>
 <link rel="stylesheet" href="menu_style.css" type="text/css" >
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>
<body bgcolor="4B51BA">
<table border=0 width=100% bgcolor="Black" >
<tr>
<td rowspan=3>
<!--<img src="admas.jpg" width=50% height=65% alt=" " border="0"></a></td>-->
<td align=center><font face="algerian" size=7 color ="White">NIVEDI</font></td></tr>

<tr><td><div>
 <ul class="menu"> 

    <li class="top"><target="main" class="top_link"><span>STATE</span></a>

    <select name = "disease">
  <option value="MVM">KARNATAKA</option>
  <option value="ECTRO">MAHARASHTRA</option>
  <option value="LCMO">ANDHRA PRADESH</option>
  <option value="MUV">TAMILNADU</option>
  <option value="KRV">ASSAM</option>
</select>
    </li>

        <li class="top"><target="main" class="top_link"><span>DISTRICT</span></a>
        <select name = "disease">
        <option value="MVM">KARNATAKA</option>
  <option value="ECTRO">MAHARASHTRA</option>
  <option value="LCMO">ANDHRA PRADESH</option>
  <option value="MUV">TAMILNADU</option>
  <option value="KRV">ASSAM</option>
  </select>
        </li>
            <li class="top"><a href="dataentry.php" target="main" class="top_link"><span>ADJ DISTRICT</span></a></li>
                    <li class="top"><a href="dataentry.php" target="main" class="top_link"><span>DISEASE NAME</span></a></li>
                        <li class="top"><target="main" class="top_link"><span>YEAR</span></a>
                        <select name = "year">
                        <option value="MVM">1987</option>
  <option value="ECTRO">1988</option>
  <option value="LCMO">1989</option>
  <option value="MUV">1990</option>
  <option value="KRV">1991</option>
  <option value="MVM">1992</option>
  <option value="ECTRO">1993</option>
  <option value="LCMO"> 1994</option>
  <option value="MUV">1995</option>
  <option value="KRV">1996</option>
  <option value="MVM">1997</option>
  <option value="ECTRO">1998</option>
  <option value="LCMO">1999 </option>
  <option value="MUV">2000</option>
  <option value="KRV">2001</option>
  <option value="MVM">2002</option>
  <option value="ECTRO">2003</option>
  <option value="LCMO">2004 </option>
  <option value="MUV">2005</option>
  <option value="KRV">2006</option>
  <option value="MVM">2007</option>
  <option value="ECTRO">2008</option>
  <option value="LCMO"> 2009</option>
  <option value="MUV">2010</option>
  <option value="KRV">2011</option>
  <option value="MVM">2012</option>
  <option value="ECTRO">2013</option>
  <option value="LCMO">2014 </option>
  <option value="MUV">2015</option>
  <option value="KRV">2016</option>
  <option value="MVM">2017</option>
  <option value="ECTRO">2018</option>
  <option value="LCMO">2019 </option>
  <option value="MUV">2020</option>


                        </li>
                            <li class="top"><a href="dataentry.php" target="main" class="top_link"><span>NO OF OUTBREAKS</span></a></li>



    <li class="top"><a href="CDance.html"  target="main" class="top_link"><span>DATA SEARCH</span></a></li>

    <!--<li class="top"><a href="help.html"  target="main" class="top_link"><span>help</span></a>
    </li>
        <li class="top"><a href="AboutUs.html"  target="main" class="top_link"><span>About Us</span></a></li>
    <li class="top"><a href="Contact.html"  target="main" class="top_link"><span>Contact</span></a></li>
    <li class="top"><a href="feedback1.php"  target="main" class="top_link"><span>Feedback</span></a></li>
    <li class="top"><a href="login.php"  target="main" class="top_link"><span>Login</span></a></li>
    <li class="top"><a href="signup.php"  target="main" class="top_link"><span>Sign Up</span></a></li>
    -->
    </tr>
    </td>
</ul>
</div></table></body>
</html>

2 个答案:

答案 0 :(得分:0)

使用AJAX。

例如,如果您的选择由不同的PHP文件填充,即districtDropdown.php,那么您可以使用GET将状态传递给它。然后你可以通过将stateID传递给zoneDropdown.php来重新填充每次选择状态时的区域下拉列表,这应该返回select元素“districtDropdownSelect”。


function displayDistrictDropdownWithState(stateID) {

if (stateID=="") { document.getElementById("districtDropdownSelect").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("districtDropdownSelect").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","/districtDropdown.php?stateID="+stateID,true); xmlhttp.send();

}

希望这会有所帮助。祝你好运。

答案 1 :(得分:0)

使用jquery函数show()和hide()使特定状态的下拉列表框可见。

if($("#state option:selected").text()=="karnataka")
{
    $("#district_kartnaka").show();
}
else
{
    $("#district_kartnaka").hide();
}
像这样,如果选择了特定的状态,则使下拉框变为可见。