0
我已創建動態引導窗體。輸入字段正在通過點擊'添加字段'按鈕來創建。現在我試圖將選擇框的值放入同一父div的相應文本框中。但我沒有這樣做。我的代碼如下:在更改動態選擇框上將值附加到文本框
<div class="input_fields_wrap_credit ">
<div class="form-group">
<h3>Credit/Deposit <a href="#add_credit_control" class="add-btn pull-right add_credit_field_button"><i class="fa fa-plus-circle"></i> add credit field</a></h3>
</div> <!-- /form-group -->
<div class="form-group">
<div class="form-input col-md-2">
<input id="cr_ac_no" name="cr_ac_no[]" type="text" placeholder="Account no." class="form-control input-sm" required="" value="">
</div>
<div class="form-input col-md-6 col-xs-12 ">
<select name="cr_gl_head[]" class="form-control cr_gl_head"><?=$accounts->GET_CHART_OF_AC()?></select>
</div> <!-- /controls -->
<div class="form-input col-md-3 col-xs-12 ">
<input type="text" name="cr_amount[]" class="form-control cr_amt" maxlength="10" placeholder="Amount">
</div> <!-- /controls -->
<a href="#" class="remove_field"><i class="fa fa-remove"></i></a>
</div><!--form-group -->
</div>
JQUERY:
<!--credit -->
<script type="text/javascript">
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap_credit"); //Fields wrapper
var add_button = $(".add_credit_field_button"); //Add button ID
var y = 1; //initlal text box count
$(wrapper).on('click','.add_credit_field_button',function(e){ //on add input button click
e.preventDefault();
if(y < max_fields){ //max input box allowed
y++; //text box increment
$(wrapper).append('<div class="form-group"><div class="form-input col-md-2"><input id="cr_ac_no" name="cr_ac_no[]" type="text" placeholder="Account no." class="form-control input-sm" required="" value=""></div><div class="form-input col-md-6 col-xs-12 "><select name="cr_gl_head[]" class="form-control cr_gl_head"><?=$accounts->GET_CHART_OF_AC()?></select></div> <!-- /controls --> <div class="form-input col-md-3 col-xs-12 "><input type="text" name="cr_amount[]" class="form-control cr_amt" maxlength="10" placeholder="Amount"></div> <!-- /controls --><a href="#" class="remove_field"><i class="fa fa-remove"></i></a></div><!--form-group -->'); //add input box
$('#num_cr').val(y); //number of credit field
}else{
alert('Maximum allowed 10 fields.');
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); y--;
})
});
</script>
//append ac no. to text box
<script type="text/javascript">
$(document).ready(function() {
var wrapper = $(".input_fields_wrap_credit"); //Fields wrapper
$(wrapper).on("change",".cr_gl_head", function(e){ //user click on remove text
e.preventDefault();
var ac_no = $(this).val();
var txt = $(this).parent('div').find('#cr_ac_no').val(ac_no);
});
});
</script>
任何幫助嗎?
試試這個代碼 - VAR的txt = $(本).parent( 'div.form組')找到( '#cr_ac_no')。 VAL(ac_no); –
親愛的mukesh Ram,我做了一些改變。 var txt = $(this).parent()。parent()。find(「input [id ='cr_ac_no']」)。val(ac_no); –