簡體   English   中英

如何使用JavaScript將多個下拉列表選擇的值提取到單個數組中

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

我正在嘗試使用JavaScript動態地將下拉列表的值提取到節點列表中。 在此代碼中,所有下拉列表均已動態創建,並將值輸入到單個節點列表數組中。 但是我的查詢是如何動態使用。 誰能建議我。

請幫忙..

感謝前進...

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

我沒有深入研究您的代碼,但僅看一眼就好像您做錯了一切。

從列表中獲取項目並在服務器端對其進行解析。 您應該使用ajax在服務器和前端之間進行通信。 看看這個https://www.w3schools.com/php/php_ajax_php.asp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM