我想组合三个javascript变量,并将其作为默认值显示在文本框中



html表单代码

<form action="code.php" method="POST" enctype="multipart/form-data">
<div class="form-group col-md-12 mb-2">
<label for="fname" class="form-label">Select District Name<span class="font-weight-bold text-danger">*</span></label>
<select id="dist" name="distcode" class="form-select" require>
<option class="active">Select District Name</option>
<?php
include '../mysqli_connect.php';
$sql = "SELECT * FROM tb_district";
$result = $con->query($sql);
if ($result->num_rows > 0) { 
// output data of each row
while($row = $result->fetch_assoc()) { 
?>
<option value="<?php echo $row['dist_code']; ?>"><?php echo $row['dist_name']; ?></option>";
<?php
}
} 
?>
</select>
</div>
<div class="form-group col-md-12 mb-2">
<label for="fname" class="form-label">Select Block Name<span class="font-weight-bold text-danger">*</span></label>
<select id="block" name="blockname" class="form-select">
<option class="active">Select Block Name</option>
</select>
</div>
<div class="form-group col-md-12 mb-3">
<label for="fname" class="form-label">Select Panchayat Name<span class="font-weight-bold text-danger">*</span></label>
<select id="panchayat" name="panchayatname" class="form-select">
<option class="active">Select Panchayat</option>
</select>
</div>

<div class="form-group col-md-12 mb-2">
<label for="fname" class="form-label">USERID<span class="font-weight-bold text-danger">*</span></label>
<input type="text" class="form-control" id="panchayat" name ="blockcode"  readonly >
</div>
<div class="form-group col-md-12">
<button type="submit" name="save_excel_data" class="btn btn-primary mt-3">Import</button>
</div>
</form>

与负载相关的下拉列表的Javascript是

$('#dist').click(function() {
//Get selected Country ID
var distid = $(this).val();
$.ajax({
type      : 'POST',
url       : '../adddistblockpanchayat/load-distblockajax.php',
data      : 'dist='+distid, //pass country data
success   : function(data) {
$('#block').html(data);
}
});
});
$('#block').click(function() {
//Get selected Country ID
var blockid = $(this).val();
$.ajax({
type      : 'POST',
url       : '../adddistblockpanchayat/load-distblockajax.php',
data      : 'block='+blockid, //pass country data
success   : function(data) {
$('#panchayat').html(data);
}
});
});

现在,我想组合依赖下拉列表的值,并显示这是一个文本框。

有两种方法。

  1. 在后端分离所有值,并使用concatenate运算符连接它们。然后用一个请求获取该值。

  2. 提取前端的值,并将这些值与+连接。下面是一个小演示:

    value1=data.val1; //data object is fetched on successful request value2=data.val2; $("textboxselector").val(value1+value2);

[再次]对不起,我漏掉了你代码中的另一部分。您似乎想要从两个不同的请求中获取值。在这种情况下,您应该全局地编写两个变量(在两个请求之前(,并将它们连接在一起。

最新更新