2013-02-15 49 views
0

我面臨使用jquery appendo插件的問題,我已經克隆了字段,但是我想根據從下拉列表中選擇的內容填充文本字段,我有一個下拉列表的產品,當我選擇一個,它旁邊的文本字段必須填寫相應的比率。我能夠通過更改從服務器端帶來數據的下拉列表來激活ajax事件,但我無法填充相鄰的文本字段。這是我的代碼。jquery appendo插件

<script type="text/javascript" lang="javascript" src="jquery-1.8.2.min.js" ></script> 
<script type="text/javascript" lang="javascript" src="jquery.appendo.js" ></script> 
<script type="text/javascript" lang="javascript"> 
    $(document).ready(function(){ 

     $('.product').change(function(){ 
      //ajax call and receiving the data but after getting the data from server how to populate the rate text field 
     }); 
     var id = 0; 
     var append = $('#objid').appendo({ 
     allowDelete: true, 
     copyHandlers: true  
    }); 


}); 
</script> 

這是我的html零件。

<body> 
    <form action="#" method="post"> 
    <table id="objid"> 
     <thead> 
      <tr> 
       <th>Client:</th> 
       <th>Product:</th> 
       <th>Rate:</th> 
      </tr> 
     </thead> 
     <tr><td><input type="text" name="name[]"></td> 
     <td> 
      <select class="product" name="product[]"> 
       <option value="">---Select---</option> 
       <option value="web_designing">Web Designing</option> 
       <option value="hosting">Hosting</option> 
       <option value="domain">Domain</option> 
      </select> 
     </td> 
     <td><input type="text" name="rate[]" id="rate[]"/></td> 
     </tr> 

    </table> 
    <br> 
    <input type="submit" value="Submit" name="submit"> 
    </form> 
</body> 

回答

0

在代碼的一部分:

$('.product').change(function(){ 
     //ajax call and receiving the data but after getting the data from server how to populate the rate text field 
    }); 

您可以通過使用此代碼增加價值的文本字段:

$('.product').change(function(){ 
     //ajax call and receiving the data but after getting the data from server how to populate the rate text field 
     var value = ajax_received_value; 
     var $this = $(this); 
     $this.parent().next().children().val(value); 
    });