如何从选择选项中获取要输入的数据

时间:2020-10-12 14:00:54

标签: javascript php html jquery

从数据库创建选择菜单的选项。我想在输入上打印所选选项的值。下面的代码仅打印第一个选项值。我想全部打印。谢谢。

<?php 
    $sql2 = "select * from add_meta";
    $sonuc2= $conn->query($sql2);
    if($sonuc2->num_rows>0){
        while($kayitlar2 = $sonuc2->fetch_object()){
            if($kayitlar2->isim!="Renk")
            {

?>

    <select id="selectid" name="<?php $kayitlar2->isim; ?>" class="sec" onchange="degergoster()" >
    <option id="barkodd"   value=""  style="display:none;"><?php echo $kayitlar2->isim; ?> seçin</option>
    <?php
                $sql = "select * from add_barkod where kat_list in('$kayitlar2->isim')";
                $sonuc= $conn->query($sql);
                if($sonuc->num_rows>0){
                    while($kayitlar = $sonuc->fetch_object()){ 
    ?> 
            <option name="selectname1"  value="<?php echo $kayitlar->ekle_hane;?>"><?php echo $kayitlar->ekle_isim; }} ?></option>
    </select>


<?php
        }   }}
?>
<input id="e" name="varyantkod"  class="sec"> 

JavaScript代码:

function degergoster() {
    var selectkutu = document.getElementById("selectid");
    var selectkutu_value = selectkutu.options[selectkutu.selectedIndex].value;

    document.getElementById("e").value=selectkutu_value;
}

1 个答案:

答案 0 :(得分:0)

仅获取选择对象的值并将其添加到输入的值中 改变

document.getElementById("selectid");

document.getElementById("selectid").value;

这应该有效