0

我的选择由两个字段组成,文本字段只选择其中一个。这是我的代码:

 <script>
        function ProdValue(data) {
           document.getElementById("ProdName").value = data.value;
       }
 </script>

 <select name="ProdName" id="ProdName" onchange ="ProdValue(this)"> 
     <?php
             $sql = "Select * from tblProduct";
             if ($result = mysqli_query($conn, $sql));   
              while ($row = mysqli_fetch_assoc($result)) 
             { 
            echo "<option value='". $row['Brand']."', '".$row['ProductName']."'>".$row['Brand']." ".$row['ProductName']. '</option>';
            }
    ?>
</select>

我怎样才能得到 ProductName 呢?

4

2 回答 2

0

改用这个。如果两个列实际上都定义为 NOT NULL,则 CONCAT() 就足够了:

 <?php
         $sql = "Select CONCAT(Brand, ProductName) as CombineColumn from tblProduct";
         if ($result = mysqli_query($conn, $sql))
         { 
               while ($row = mysqli_fetch_assoc($result)) 
               { 
               echo "<option value='". $row['CombineColumn']."'>".$row['CombineColumn']."</option>";
               }
          }
?>
于 2013-11-07T03:29:30.953 回答
0

由于您的选项value包含用逗号分隔的品牌和产品名称,您可以这样做:

function ProdValue(data) {
   var optval = data,
   prod_name = optval.split(",")[1];
   console.log( prod_name ); //here is your product name
   document.getElementById("ProdName").value = optval;
}
于 2013-11-07T03:24:46.447 回答