普通php二级联动菜单,级联菜单
数据库结构与《ajax php二级联动菜单》相同
代码
PHP Code
- <script language = "JavaScript">
- var onecount;
- onecount=0;
- subcat = new Array();
- <?
- //类别选择
- mysql_select_db($database_lr, $lr);
- $sql = "select * from smallclass";
- $result = mysql_query( $sql );
- $count = 0;
- while($res = mysql_fetch_row($result)){
- ?>
- subcat[<?=$count?>] = new Array("<?=$res[0]?>","<?=$res[1]?>","<?=$res[2]?>");
- <?
- $count++;
- }
- echo "onecount=$count;";
- ?>
- function changelocation(locationid)
- {
- document.myform.smallclassid.length = 0;
- var locationid=locationid;
- var i;
- for (i=0;i < onecount; i++)
- {
- if (subcat[i][2] == locationid)
- {
- //var newOption1=new Option(subcat[i][1], subcat[i][0]);
- //document.all.smallclassid.add(newOption1);
- document.myform.smallclassid.options[document.myform.smallclassid.length] = new Option(subcat[i][1], subcat[i][0]);
- }
- }
- }
- </script>
- <h1 class="logo"><a href="http://www.freejs.net" title="freejs首页"><img src="../../images/logo.png" height="47" width="500" alt="freejs首页" /></a></h1>
- <div id="main_demo">
- <div align="center"><h2><a href="http://www.freejs.net/article_biaodan_30.html">普通php二级联动菜单,级联菜单</a></h2></div>
- <form method="post" name="myform" action="" onSubmit="return CheckForm();" style="text-align:center">
- 选择类别:<select name="bigclassid" onChange="changelocation(document.myform.bigclassid.options[document.myform.bigclassid.selectedIndex].value)" size="1">
- <option selected value="">选择大类</option>
- <?
- $sql = "select * from bigclass order by sort";
- $result = mysql_query( $sql );
- while($res = mysql_fetch_row($result)){
- ?>
- <option value="<? echo $res[0]; ?>"><? echo $res[1]; ?></option>
- <? } ?>
- </select>
- <select name="smallclassid">
- <option selected value="">选择小类别</option>
- </select>
- </form>
原文地址:http://www.freejs.net/article_biaodan_30.html