gpt4 book ai didi

javascript - 编辑记录时显示所选值

转载 作者:可可西里 更新时间:2023-11-01 08:23:37 26 4
gpt4 key购买 nike

编辑记录时,我希望下拉列表显示之前选择的值。

代码如下:-

<div class="modal fade" id="edit_model" tabindex="-1" role="dialog"  aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title" >Model Title</h6>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form action="filename.php" method="post">
<div class="form-group row">
<div class="col-md-1"></div>
<div class="col-md-3">
<input type="text" name="first_name" placeholder="First Name" id="first_name" class="form-control rs_input" required >
</div>
<div class="col-md-3">
<input type="text" name="last_name" placeholder="Last Name" id="last_name" class="form-control rs_input" required >
</div>
<select class="form-control" id="dropdown_id" name="dropdown_name">
<option >Select Value</option>

<?php
$dropdown = mysqli_query($connect, "SELECT * FROM table") or die(mysqli_error($connect));
while ($fetch_data = mysqli_fetch_array($country)) {
?>
<option value="<?php echo $fetch_data['id']; ?>"><?php echo $fetch_data['name']; ?></option>
<?php
} ?>
</select>
</div>
</div>
</div>
</div>
</div>

Jquery:-

$('.class_name').on('dblclick',function(){
var value = $(this).attr("id");

$.ajax({
url:"ajax/filename.php",
method:"POST",
data:{value:value},
dataType:"json",
success:function(data){

$('#first_name').val(data.first_name);
$('#last_name').val(data.last_name);
$('#dropdown_id').val(data.dropdown_value);
)};
)};

为了澄清,我希望在用户编辑记录时在下拉列表中选择先前选择的值,即记录中存在的值。任何帮助表示赞赏。

最佳答案

您需要指定 selected 标签,否则它只会填充下拉列表。

因此,在循环值时,如果您需要检查必须选择哪个值(如果它是用户特定的)。

if (some condition)
{
<option selected="selected" ...
}
else
{
<option ...
}

关于javascript - 编辑记录时显示所选值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53912399/

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