duanliaoyu8419 2012-10-23 10:14
浏览 38

通过SQL动态更改下拉列表并计算总和?

I've got a row in a table with 3 fields laid out as so:

Job            Pay Grade       Cost
<Select>       <Select>        <Calculation>

I've got an SQL table with the information above in it, for example:

Job            Pay Grade       Cost
Techie         1               100
Techie         2               200
Engi           2               300
Engi           3               400
Engi           4               500

What I need to do is to be able to select a Job from the dropdown and then the Pay Grade select box will change depending on what matches that job in the SQL database. It will then show the cost which relates to the to selected.

How can I go about this as I am a little stuck

  • 写回答

2条回答 默认 最新

  • duanchi5078 2012-10-23 10:33
    关注

    You need to post the select job via $.ajax and then in success function populate the dropdown list like this:

    function selectHandler (event, ui)
            {
            var id = event.target.id;
            $.ajax({
                    type: "POST",
                    url: "/php/get_quantity_type.php",
                    dataType:"json",
                    data: { ingridient : ui.item.value},
                    success: function(data){$("#"+id+"_t").empty(); $.each(data,function(index,value) {$("#"+id+"_t").append('<option value="' + value + '">' + value + '</option>');})}
                    });
            } 
    

    This example takes a name of a material from select list posts it via $ajax() to a php script and writes it down to a new dropdown list which id is based on id that triggered the event. If you need the php code just ask:)

    You bind your job list to the event handler above:

    ("#job_list").bind("select",selectHandler);
    

    This code posts data to "/php/get_quantity_type.php", and passess the result to function declared in success attribute;

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号