【问题标题】:Basics of dynamic loading a drop down box动态加载下拉框的基础知识
【发布时间】:2012-04-10 19:56:47
【问题描述】:

我是 php/ajax 和某种程度上 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.有人可以向我指出一些不太令人困惑的简单示例。我知道ajax最适合这个。

脚本

  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';
}

页面

       <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>

【问题讨论】:

    标签: php mysql ajax drop-down-menu


    【解决方案1】:

    这很简单

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

    当用户从下拉列表中选择值时

    所需的java脚本函数

     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);
          });
        }
    

    //您的 ajax/test.php 将为下拉菜单创建内容

    【讨论】:

    • 我尝试了以下方法,但它不起作用。如果选择 forward 打开另一个下拉框,如果选择 forward 它打开一个 txt 框。
    • @user969733 你可以添加更多的盒子,或者任何你想要的东西,比如这些时尚
    • 这是什么问题,还需要通过代码进行一些调试
    • 如果我选择第二个选项,它不会显示下拉列表,它会同时显示!
    • 应该是这样 if(name=='forwardorder')document.getElementById('div2').style.display="block";否则 document.getElementById('div1').style.display="none";您正在显示 div1 和 hising 相同的 div1 ,这是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-16
    • 2018-05-25
    • 2014-11-28
    • 2014-02-14
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多