gpt4 book ai didi

javascript - 选择第一个选择框值后填充第二个选择框,如何在脚本中选择要编辑的值

转载 作者:行者123 更新时间:2023-11-27 23:53:10 24 4
gpt4 key购买 nike

html

<div class="form-group">
<label for="" class="control-label col-xs-2">
<?php echo $this->lang->line('country'); ?>
</label>
<div class="col-md-6">
<select class="form-control" id="edu" name="country">
<option value="">Select</option>
<option value='United Kingdom' <?php echo set_value( 'country', $row->Country) == 'United Kingdom' ? "selected" : "";?>>United Kingdom</option>
<option value='Canada' <?php echo set_value( 'country', $row->Country) == 'Canada' ? "selected" : "";?>>Canada</option>
<option value='Others' <?php echo set_value( 'country', $row->Country) == 'Others' ? "selected" : "";?>>Others</option>
</select>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-xs-2">
<?php echo $this->lang->line('location'); ?>
</label>
<div class="col-md-6">
<select class="form-control" id="edct" name="location">
<option value="">Select</option>

<script>
var eduBak = {};
eduBak['United Kingdom'] = ['England', 'Northrn Ireland', 'Scotland', 'Wales', 'other'];
eduBak['Canada'] = ['Alberta ', 'Brirish Columbia', 'Manitoba', 'others'];
eduBak['Others'] = ['Others']

$('#edu').on('change', function() {
var edu = document.getElementById("edu");
var model = document.getElementById("edct");
var educ = edu.value;
while (model.options.length) {
model.remove(0);
}
var ed = eduBak[educ];
if (ed) {
var i;
for (i = 0; i < ed.length; i++) {
var e = new Option(ed[i], ed[i]);
model.options.add(e);
}
}
});
</script>
</select>
</div>
</div>

我正在尝试从数据库获取第二个选择框值以继续我的编辑/更新部分。对于通常的选择框,我一直在使用以下方法。

 <select>
<option value="">Select</option>
<option value='Somewhere' <?php echo set_value( 'country', $row->Country) == 'Somewhere' ? "selected" : "";?>>Somewhere</option>
</select>

现在我需要从数据库中获取第二个选择框。 。我不知道将此添加到我的脚本代码中。任何人都可以帮助我解决这个问题。 。 ?

最佳答案

<div class="form-group">
<label for="" class="control-label col-xs-2">
<?php echo $this->lang->line('country'); ?>
</label>
<div class="col-md-6">
<select class="form-control" id="edu" name="country">
<option value="">Select</option>
<option value='United Kingdom' <?php echo set_value( 'country', $row->Country) == 'United Kingdom' ? "selected" : "";?>>United Kingdom</option>
<option value='Canada' <?php echo set_value( 'country', $row->Country) == 'Canada' ? "selected" : "";?>>Canada</option>
<option value='Others' <?php echo set_value( 'country', $row->Country) == 'Others' ? "selected" : "";?>>Others</option>
</select>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-xs-2">
<?php echo $this->lang->line('location'); ?>
</label>
<div class="col-md-6">
<select class="form-control" id="edct" name="location">
<option value="">-select-</option>;
<?php if(isset($row))
{?>

<option value="<?php echo $row->Location;?>" selected><?php echo $row->Location;?></option>
<?php }?>

</select>
<script>
var eduBak = {};
eduBak['United Kingdom'] = ['England', 'Northrn Ireland', 'Scotland', 'Wales', 'other'];
eduBak['Canada'] = ['Alberta ', 'Brirish Columbia', 'Manitoba', 'others'];
eduBak['Others'] = ['Others']

$('#edu').on('change', function() {
$("#edct > option").remove();
var edu = document.getElementById("edu");
var model = document.getElementById("edct");
var educ = edu.value;
while (model.options.length) {
model.remove(0);
}
var ed = eduBak[educ];
if (ed) {
var i;
for (i = 0; i < ed.length; i++) {
var e = new Option(ed[i], ed[i]);
model.options.add(e);
}
}
});
</script>
</div>
</div>

这个方法对我有用。

关于javascript - 选择第一个选择框值后填充第二个选择框,如何在脚本中选择要编辑的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32519684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com