When user selects channel name from dropdown list , i want to set its channel type to the text box in dynamically created row. I am creating multiple rows on addRow event. It is working fine
This is html code
<table id="dataTable" border="1" class="table table-striped table-bordered" >
<tr>
<td><INPUT type="checkbox" name="chk[]" data-parsley-errors-container="#checkbox-errors" /></td>
<td>
<SELECT name="channel_name[]" onclick ="get_type(this)"; class='channelname'>
<option value="">Select...</option>
<?php foreach($channel_list as $row) {
$channelid = $row['channelid'];
$channelname = $row['channelname'];?>
<OPTION value='<?php echo $channelid ?>'><?php echo $channelname?></OPTION>
<?php } ?>
</SELECT>
</td>
<td><INPUT type="text" name="type[]" class="channeltype"/></td>
<td><INPUT type="text" name="partner_share[]"/></td>
</tr>
</table>
Javascript Code :
function get_type()
{
$(".channelname").live("change", function() {
var channel_id = $(this).find("option:selected").attr("value");
$.ajax({
type: "POST",
url: '<?php echo base_url(); ?>index.php/partner/get_channel_type',
data: 'channelid='+channel_id,
async: false
}).done(function( data1 ) {
if(data1){
alert(data1);
//$(this).closest('tr').children('td.type').val(data1);
//$(this).closest('tr').find('.type').val(data1);
$(this).closest("tr").find('input[name="channeltype[]"]').val(data1);
//$(this).closest("tr").find('input[name="usage_unit[]"]').val(ui.item.usage_unit);
}else{
alert("Channel type is not defined");
}
});
});
}