简体   繁体   English

如何使用JavaScript将多个下拉列表选择的值提取到单个数组中

[英]How to fetch multiple dropdowns selected value into a single array using JavaScript

I am trying to fetch values of drop-downs into a node-list having dynamically using a JavaScript. 我正在尝试使用JavaScript动态地将下拉列表的值提取到节点列表中。 In this code all the drop down have created dynamically and entering the value in a single node-list array. 在此代码中,所有下拉列表均已动态创建,并将值输入到单个节点列表数组中。 But my query is how to use dynamically. 但是我的查询是如何动态使用。 Can anyone suggest me. 谁能建议我。

please help.. 请帮忙..

thanks for advance... 感谢前进...

<?php 
    $j=1;
    $proQuery=$this->db->query("select * from tbl_subcategory where category_id='$getInv->catg_id' and whr_to_use='for bom'");
    foreach($proQuery->result() as $proRow){
?>
<tr>
    <th style="width:200px"><?php $techQuery=$this->db->query("select * from tbl_technical_category where sub_catg_id='$proRow->subcategory_id'");
    //echo $proRow->subcategory_id;
    $i=1;
    foreach($techQuery->result() as $techRow){//echo $techRow->techcategory_id;
?>
        <select name="tech_prod" id="tech_prod<?=$j."^".$i;?>" class="form-control" required onchange="raptoit(this.id)" <?php if(@$_GET['view']!=''){ ?> disabled="disabled" <?php }?>>
            <option value="" selected disabled><?php echo $techRow->tech_catg_name;?></option>
            <?php $contQuery=$this->db->query("select * from tbl_technical_product where technical_sub_type='$techRow->techcategory_id'");
                $k=1;
                foreach($contQuery->result() as $contRow){
            ?>
            <option value="<?php echo $contRow->technical_pro_id; ?>"><?php echo $contRow->tech_pro_name; ?></option>
            <?php $k++;} ?>
        </select><?php $i++;}?>
        <input type="text" id="techId<?=$j;?>" name="techId[]" value="" readonly="" class="form-control"> 
    </th>
</tr>
<?php $j++;}?>
<script>
    function raptoit(d){
        var zz=document.getElementById(d).id;
        //alert(zz);
        var myarra = zz.split("^");
        var asx= myarra[1];
        var asx11= myarra[0];
        var value=asx11.split("tech_prod");
        var mainId=value[1];
        //alert(mainId);
        // all select element.
        var merge=document.getElementById(asx11+"^"+asx).value;
        //alert(dropValue);
        // convert nodeList to array
        var nodesArray = [].slice.call(document.querySelector("select"));
        //alert(nodesArray);
        var result = nodesArray.map(select => {return select.value;}).join(',');
        alert(result);
        document.getElementById("techId"+mainId).value=result;
    }
</script>

I have not looked in depth into your code but from a mere glance it seems you are doing it all wrong. 我没有深入研究您的代码,但仅看一眼就好像您做错了一切。

To get the items from the list and parse them on the server side. 从列表中获取项目并在服务器端对其进行解析。 You should use ajax to communicate between the server and frontend. 您应该使用ajax在服务器和前端之间进行通信。 Look at this https://www.w3schools.com/php/php_ajax_php.asp 看看这个https://www.w3schools.com/php/php_ajax_php.asp

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

相关问题 如何在 javascript 中获取多个下拉菜单中的选定选项 - How to fetch selected option in javascript for more than one dropdowns 如何使用JavaScript获取按钮的选定值 - How to fetch selected value of button using javascript 使用javascript根据其他下拉列表中的选定值启用或禁用下拉列表 - Enable or disable dropdowns based on selected value in other dropdown using javascript 如何使用下拉菜单在JavaScript中实现多个过滤器 - How to implement multiple filters in JavaScript using dropdowns jQuery,如何使用同一类为多个下拉菜单获取先前选择的下拉列表值? - Jquery, how to get previous selected dropdown value for multiple dropdowns using the same class? 使用单个触发器更改多个下拉列表的选定选项 - Change the selected option of multiple dropdowns with a single trigger 填充多个下拉列表后如何设置正确的值? - How to set the right value as selected after populating multiple dropdowns? 如何从多个 url 中获取数据并将其存储在 javascript 中的单个数组中? - How to fetch data from multiple url and store it in single array in javascript? 如何使用 jquery 将下拉列表的选定选项的 ID 推送到数组中? - How to push the ids of selected option of dropdowns into an array using jquery? 从多个下拉列表中选择值 - Getting selected value from multiple dropdowns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM