2012-03-27 125 views
0

我是新来的PHP/Ajax和在一定程度上SQL。我试图添加一个动态下拉框,当选择将加载另一个下拉框与日期或另一个文本框。有人能指点我一些简单的例子,不是很混乱。我明白,阿贾克斯是最好的。基础下拉框

脚本

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> 

回答

2

这是非常简单的

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

<div id="populate"></div> 

当用户选择从下拉

01值

需要的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的将创建下拉

+0

我已经尝试以下,但它不会工作内容。如果向前选择打开另一个下拉框,如果通过向前选择打开一个txt框。 – 2012-03-27 12:43:24

+0

@ user969733您可以添加多个框,或任何你想要这样的时尚 – 2012-03-27 12:44:43

+0

我已经附上了我的代码 – 2012-03-27 12:46:16