dongyi9023 2012-03-27 09:39 采纳率: 0%
浏览 35

动态加载下拉框的基础知识

I'm new to php/ajax and to an extent sql. I'm trying to add a dynamic drop down box which when select will either load up another drop down box with dates or another text box. Can someone point me towards some simple examples that are not very confusing. I understand that ajax is best for this.

script

  function showfield(name){
 if(name=='byreturn')document.getElementById('div1').style.display="block";
 else document.getElementById('div1').style.display="none";
 }

if(name=='forwardorder')document.getElementById('div2').style.display="block";
else document.getElementById('div2').style.display="none";
}


  function hidefield() {
document.getElementById('div1').style.display='none';
}

page

       <tr><td> <body onload='hidefield()'>
                Choose Delivery Type </td>
               <td> <select name = 'elementtype1'id='elementtype1' onchange='showfield(this.options[this.selectedIndex].value)'>
                        <option value='forwardorder'>Forward Order</option>
                        <option value='byreturn'>By Return</option>
                        </select></td>
                        <td>

                        <div id='div1'>Enter By Return Date<input type='text''name='whatever1' />
                        </div>

                        <div id='div2'>
                        <td>Capacity</td>
                        <td><select name='deliveryDate'>
                        $listCapacityDates = $cid->ListCapacity();
                        foreach($listCapacityDates as $x) {
                        <option value='" . $x[cap] . "'</option>;
                        </div>
                        </td></tr>
  • 写回答

1条回答 默认 最新

  • dptrmt4366 2012-03-27 09:49
    关注

    This is very simple

    <select name="first" onChange="populateNextBox(this)">
     <options value="1">Microsoft</options>
     <options value="2">Oracle</options>
    </select>
    
    <div id="populate"></div>
    

    When user select the value from the drop down

    required java script function

     function populateNextBox(e) {
          alert(e.value); //will print the selected value
          //used jquery for populating data
          $.post('ajax/test.php?id='+e.value, function(data) {
              $('#populate').html(data);
          });
        }
    

    //Your ajax/test.php will create the content for the dropdown

    评论

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择