duan01203 2017-05-29 09:05
浏览 54

如何从数据库中获取Textbox中的值取决于没有提交按钮的下拉列表

I want to get the text box value from database depends upon the dropdownlist values without using submit button .Now I have three dropdown list on my code.how can i write the javascript for three dropdown

<div align="center">
<table>
<thead>
<th>Product</th>
<th>Quantity</th>
<th>Rate</th>
<th>Amount</th>
</thead>
<tbody>
    <tr id="addrow">
    <td>
    <?php
    $selectproduct=mysql_query("select productname from items");
    $itemname=mysql_fetch_array($selectproduct);
    ?>
    <select name="item[]" id="item">

    <?php
    $i=0;
    while($itemname=mysql_fetch_array($selectproduct))
    {
    ?>
      <option value="<?php echo $itemname['productname'];?>"><?php echo $itemname['productname'];?></option>
      <?php
     $i++;
    }
    ?>
    </td>
    <?php

 //    $amount=mysql_query("select Amount from items where Productname='$productname' ");
   //  $totalamount=mysql_fetch_array($amount);
    ?>


    <td><input class="qty" type="text" name="qty[]"></td>
    <td><input class="price" type="text" name="price[]"></td>
    <td><input type="text" class="output" name="output[]"></td>
    </tr>
    <tr >
    <td>
    <?php
    $selectproduct=mysql_query("select productname from items");
    $itemname=mysql_fetch_array($selectproduct);
    ?>
    <select name="item[]" id="item">

    <?php
    $i=0;
    while($itemname=mysql_fetch_array($selectproduct))
    {
    ?>
      <option value="<?php echo $itemname['productname'];?>"><?php echo $itemname['productname'];?></option>
      <?php
     $i++;
    }
    ?>
    </td>

    <td><input class="qty" type="text" name="qty[]"></td>
    <td><input class="price" type="text" name="price[]"></td>
    <td><input type="text" class="output" name="output[]"></td>
    </tr>
    <tr>
    <td>
    <?php
    $selectproduct=mysql_query("select productname from items");
    $itemname=mysql_fetch_array($selectproduct);
    ?>
    <select name="item[]" id="item">

    <?php
    $i=0;
    while($itemname=mysql_fetch_array($selectproduct))
    {
    ?>
      <option value="<?php echo $itemname['productname'];?>"><?php echo $itemname['productname'];?></option>
      <?php
     $i++;
    }
    ?>
    </td>

   <td><input class="qty" type="text" name="qty[]"></td>
    <td><input class="price" type="text" name="price[]"></td>
    <td><input type="text" class="output" name="output[]"></td>
    </tr>
</table>
<div id="grand">
Total Amount:<input type="text" name="gran" id="gran">
</div>
    </tr>
    <tr >
    <td colspan="4">
    <center><input type="submit" name="submit"></center>
    </td>
    </tr>
</tbody>
</table>
</div>
</form>
</body>
<script type="text/javascript">
    $(document).ready(function() {
    $(".price").keyup(function() {
        var grandTotal = 0;
        $("input[name='qty[]']").each(function (index) {
            var qty = $("input[name='qty[]']").eq(index).val();
            var price = $("input[name='price[]']").eq(index).val();
            var output = parseInt(qty) * parseInt(price);

            if (!isNaN(output)) {
                $("input[name='output[]']").eq(index).val(output);
                grandTotal = parseInt(grandTotal) + parseInt(output);    
                $('#gran').val(grandTotal);
            }
        });
    });
}); 
</script>
  • 写回答

2条回答 默认 最新

  • dsff788655567 2017-05-29 09:10
    关注

    I recommand you to use jQuery for start. It is easier to manipulate the DOM. Follow a tutorial and then, attach a callback on the change event on your dropdown menus, then in the callback get the values for your menu in an ajax call, then generate the html (the option tags) and update your select.

    The Ajax call and the html update can be done with jQuery, but you can do it by yourself in pure Javascript as well.

    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂