基于第一个选择框的PHP自动更新选择框 [英] PHP Auto update selectbox based on 1st selectbox
问题描述
我有2个选择框
< h3>结果< / h3>
< option value =Rugby>橄榄球< / option>
< option value =Cricket>板球< / option>
< option value =Football> Football< / option>
< / select>
<?php
echo'< select name =match>';
echo'< option value ='。$ row ['event_id']。'>'。$ row ['team1']。'VS'。$ row ['team2']。'< ; /选项>';
echo'< / select>';
?>
< input id =register_formtype =submitvalue =Displayname =submit/>
用户通过以下方式搜索结果:
在第一个选择框中选择运动类型,然后在第二个选择框选项值中填充基于运动类型。
是否可以在PHP中执行此操作,而用户不必先按提交获取运动类型的$ _POST值?
这里我的最佳选择是什么?
是您要求的唯一选项(无需刷新页面)
-
当您使用php时,只能使用页面刷新。但没有页面刷新的Ajax是可能的。
帮助链接是:
https://remysharp.com/2007/01/20/auto-populating-select-boxes -using-jquery-ajax
I have 2 selectboxes
<h3>Results</h3>
<select id="register_form" name="sport" />
<option value="Rugby">Rugby</option>
<option value="Cricket">Cricket</option>
<option value="Football">Football</option>
</select>
<?php
echo'<select name="match">';
echo'<option value="'.$row['event_id'].'">'.$row['team1'].' VS '.$row['team2'].'</option>';
echo'</select>';
?>
<input id="register_form" type="submit" value="Display" name="submit" />
User searches for a result by:
selecting sport type in 1st selectbox and then in 2nd selectbox option values are populated based on sport type.
Is it possible to do this in PHP without the user having to first press submit to get the $_POST value of sport type?
What is my best option here?
1.Ajax is the only option what you asked for that(without page refresh)
When you use php it's only possible with page refresh. but with ajax without page refresh it's possible.
helping links are:-
Use jQuery to change a second select list based on the first select list option
https://www.daniweb.com/web-development/php/threads/372228/php-and-ajax-auto-populate-select-box
https://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax
这篇关于基于第一个选择框的PHP自动更新选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!