2012-03-27 59 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