douchujian8124 2016-09-18 06:52 采纳率: 100%
浏览 72

在文本框html中插入值选择

I read the discussion on how to check outstretched by HTML select and add in HTML text input.

Does not work in my case having a select dynamic that takes while loop with the data from DB. Could you help me find a solution?

I want to display the value and the text that is chosen in the select, in the form below in a text field.

   <select name="auto" id="auto">
    <option value="false">Auto non presente</option>
     <?php while ($row = mysqli_fetch_array($result_modello)):; ?>
       <option value="<?php echo $row['id_modello']; ?>"><?php echo $row['nome_modello']; ?></option>
     <?php endwhile; ?>
  </select>
  <select name="marca">
    <option value="false">Marca non presente</option>
     <?php while ($row = mysqli_fetch_array($result_marca)):; ?>
       <option value="<?php echo $row['id_marche']; ?>"><?php echo $row['nome_marche']; ?></option>
     <?php endwhile; ?>
  </select>
  • 写回答

5条回答 默认 最新

  • dongluojiao6322 2016-09-18 06:57
    关注

    Try this :

    $("input[type=text]").val($("select[name=marca]").val());
    

    Or

     $("input[type=text]").val($("#auto").val());
    

    If you want display both select use this :

    var one = $("#auto").val();
    
    var two = $("select[name=marca]").val();
    
    $("input[type=text]").val(one + " , " + two);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line