Home > Backend Development > PHP Tutorial > Use php+JS to create secondary menu navigation

Use php+JS to create secondary menu navigation

怪我咯
Release: 2023-03-12 20:06:01
Original
2054 people have browsed it

I made the second-level cascading menu using asp+js last year, but when I suddenly took it out and made it again, I found that I had forgotten it, and the original program written in asp could not be found. I was really dizzy. [emot]sweat[/emot], so I searched online for a long time. I found that the writing methods on the Internet are different, and they are all very complicated. Is it necessary to make such a two-level cascading menu so complicated? So I wanted to rewrite a simple one. After thinking about it for about half an hour, I completed the design and production of the second-level cascading menu.


The general idea is this: In order to prevent the previous page from refreshing, I used an iframe to sneak into a secondary sub-page to read the data in the database, and finally pass the desired data To the parent page, complete the selection and transfer of data.

The main program code is as follows (part of the code has been changed, but it does not affect the function):
Parent page reg.html:

<iframe src=”city.php” width=”300″ height=”22″ frameborder=”0″ scrolling=”no”></iframe> <input name=”city” type=”hidden” id=”city” value=”" />
Copy after login

Sub page city.php:

<script language=”javascript” type=”text/javascript”> 
function goto(n){ 
this.location.href=”city.php?sh_id=”+n; 
} 
</script> 

<select name=”sh” onchange=”goto(this.value)”> 
<option>请选择所在省市</option> 
<?php 
include_once(”db.php”); 
$sql=”select * from province order by sh_id asc”; 
$result=mysql_query($sql); 
while($row=mysql_fetch_assoc($result)){ 
?> 
<option value=”<? echo $row[”sh_id”];?>” <? if($_GET[”sh_id”]==$row[”sh_id”]){echo &#39;selected=”selected”‘;}?>><? echo $row[”sh_name”];?></option> 
<?php 
} 
?> 
</select> 
<select name=”city” onchange=”parent.document.getElementById(&#39;city&#39;).value=this.value”> 
<option>选择你所在的城市</option> 
<?php 
if(!empty($_GET[”sh_id”])){ 
//echo “ok”; 
$sql=”select * from city where sh_id=”.$_GET[”sh_id”].” order by city_id asc”; 
$result=mysql_query($sql); 
while($row=mysql_fetch_assoc($result)){ 
?> 
<option value=”<? echo $row[”city_name”];?>”><? echo $row[”city_name”];?></option> 
<?php 
} 
} 
?> 
</select>
Copy after login


The above is the detailed content of Use php+JS to create secondary menu navigation. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template