douzhiba6873 2012-05-28 07:24
浏览 75

单击下拉列表中的项目时,自动获取文本框中的值

I have a text box and dropdown list box. In dropdown list box i'm having the list of equipments which are having the different price according to the equipment. User take the equipment for the rent for the num of days. Now I calculate the price for the rent using php function.

Now all I want is, to display that respected calculated value at the text box while clicking the respective item in a dropdown list box by calling that function in the html form using php.

Could anyone help me to fix this problem with the example?

  • 写回答

1条回答 默认 最新

  • douyi4544 2012-05-28 07:36
    关注

    Haven't tested it, and since you didn't give any more information, this is based on a php as source file which echo's the price, when called with 2 parameters:

    <html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script type="text/javascript">
            $("#items").change(function() {
                $.ajax({
                    url: "http://url/data.php",
                    data: {
                        selectedItem: $("#items").val(),
                        days: $("#days").val()
                    },
                    success: function() {
                        $("#total").html(data)
                    }
                }
            }
        </script>
    </head>
    <body>
    <form>
        <input id="days" value="1" />
        <select id="items">
            <option value="1">Object 1</option>
            <option value="2">Object 2</option>
        </select>
    
        Calculated costs: <span id="total"></span>
    </form>
    </body>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办