简体   繁体   中英

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); 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>

` And the Javascript for load dependent dropdown list is

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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