[英]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.