我正在尝试通过php实现某些目标。
这里有几个选项。
<select class="custom-select" id="inputGroupSelect01">
<option selected="">Select Clusters ...</option>
<option value="math-related">Math Related</option>
<option value="science-related">Science Related</option>
</select>
分别更改选项时,将出现“主题”字段组。
<div class="form-row pb-5" id="math-related"">
<div class="form-group col-md-3">
<input type="number" class="form-control" id="num1" placeholder="English">
</div>
<div class="form-group col-md-3">
<input type="number" class="form-control" id="num2" placeholder="Math">
</div>
<div class="form-group col-md-3">
<input type="number" class="form-control" id="num3" placeholder="Science">
</div>
<div class="form-group col-md-3">
<input type="number" class="form-control" id="num4" placeholder="Computer">
</div>
</div>
当选项更改为与数学相关或与科学相关选项时,相关的5-6个主题字段将如下图所示填充。有些可能有5,有些可能有8。
如何根据通过PHP完成的选择刷新页面并加载新的输入字段集?
答案 0 :(得分:1)
首先,使用页面url +参数更改您选择的下拉菜单,并确保按如下所示用实际url替换YOUR_PAGE_URL-
<select onChange="window.location.href=this.value" class="custom-select" id="inputGroupSelect01">
<option value="">Select Clusters ...</option>
<option value="YOUR_PAGE_URL?topic=math-related">Math Related</option>
<option value="YOUR_PAGE_URL?topic=science-related">Science Related</option>
</select>
之后,只需在页面上执行GET参数检查即可填充-
if( issset($_GET['topic']) ){
if( $_GET['topic'] == 'math-related' ){
echo "Add your math related above 5-8 fields html here.";
}elseif( $_GET['topic'] == 'science-related' ){
echo "Add your science related above 5-8 fields html here.";
}
}