简体   繁体   English

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

[英]I want to combine three javascript variable and display this in a textbox as default value

html code for form` Select District Name* Select District Name query($sql); html 表格代码 Select 区名* Select 区名查询($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) {?> if ($result->num_rows > 0) { // output 每行数据 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>

` And the Javascript for load dependent dropdown list is ` Javascript 用于负载相关的下拉列表是

<script type="text/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);
                    }
            });
});

now I want to combine the value of the dependent dropdown and display this is a textbox.现在我想组合相关下拉列表的值并显示这是一个文本框。

You have two ways to do it.你有两种方法可以做到这一点。

  1. Separate all the values in back end and join them with concatenate operator.将后端中的所有值分开并使用连接运算符将它们连接起来。 Then pull that value with a requests.然后通过请求提取该值。

  2. Pull the values in front end and join these values with + .Here is a small demo:拉取前端的值并用+连接这些值。这是一个小演示:

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

[Again] Sorry I missed another part from your code. [再次]抱歉,我错过了您代码中的另一部分。 It seems you want to get values from two different requests.您似乎想从两个不同的请求中获取值。 In this case you should write two variables globally in this case(before two requests) and join them together.在这种情况下,您应该在这种情况下(在两个请求之前)全局编写两个变量并将它们连接在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM