将数组复选框值附加到codeigniter活动记录中的表

时间:2018-09-04 17:15:26

标签: javascript ajax codeigniter activerecord

我正在使用codeigniter活动记录,并且在将复选框值添加到将出现在我的视图表中的数据库表中时遇到了困难。我希望有人可以帮助我解决这个问题。

复选框月份

<div class="col-md-12">
<div class="form-group">
    <?php foreach ($monthList as $month) { ?>
        <div class="checkbox">
            <label style="display: inline-block; max-height: 25px; list-style: none; float: left; padding-top: 5px; width: 130px; margin-right: 40px;">
            <input class="chkAdd" type="checkbox" name="month_id" value="<?php echo $month['id'] ?>" <?php echo set_checkbox('month_id', $month['id']); ?> ><?php echo $month['month_name'] ?>
            </label>
        </div>
    <?php } ?>
         <span class="text-danger"><?php echo form_error('month_id'); ?></span>
</div>

必须附加复选框值并批量插入数据库的表。

<div class="box-body col-md-12" style="padding-top: 20px;">
<div class="table-responsive">
    <table class="table table-striped table-bordered table-hover" id="feeMasterEntryTable">
        <thead>
            <tr>
                <th>Month</th>
                <th>Start Date</th>
                <th>Due Date</th>
                <th>Amount</th>
                <th>Penalty</th>
                <th class="text-right"></th></tr>
        </thead>
        <tbody class="form-horizontal" id="TextBoxContainer" role="form"></tbody>
    </table>
</div>

我的Java脚本...

<script type="text/javascript">
$(function () {
    $(document).on("click", "#chkAdd", function () {
        var lenght_div = $('#TextBoxContainer').length;
        var div = GetDynamicTextBox(lenght_div);
        $("#TextBoxContainer").append(div);
    });
    $(document).on(function () {
        var values = "";
        $("input[name=DynamicTextBox]").each(function () {
            values += $(this).val() + "\n";
        });
    });
});

function GetDynamicTextBox(value) {
    var row = "";
    $('#chkAdd:checkbox:checked:').each(function(){
    row += '<tr class="tableGroup">';
    row += '<td class="mailbox-name"><input class="form-control" name="feetype_id" value="<?php echo set_value('feetype_id', $feetype['type']); ?>"/></td>';
    row += '<td class="mailbox-name"><input class="form-control" name="startDate"  value="<?php echo set_value('startDate', $feetype['start_date']); ?>"/></td>';
    row += '<td class="mailbox-name"><input class="form-control" name="endDate" value="<?php echo set_value('startDate', $feetype['end_date']); ?>"/></td>';
    row += '<td class="mailbox-name"><input id="amountCell" name="amountCell" placeholder="" type="text" class="form-control"/></td>';
    row += '<td class="mailbox-name"><input id="penaltyCell" name="penaltyCell" placeholder="" type="text" class="form-control"/></td>';
    row += '</tr>';
    });
    row = row.substring();
    $(".tableGroup").val(row);
    return row;
}
</script>

<script type="text/javascript">
$(document).ready(function () {
    $(".feemaster_form").submit(function (e)
    {
        $("#TextBoxContainer").html("");
        $.ajax(
                {
                    url: formURL,
                    type: "POST",
                    data: postData,
                    dataType: 'json',
                    success: function (data, textStatus, jqXHR)
                    {
                        if (data.st === 1) {
                            $.each(data.msg, function (key, value) {
                                $('.' + key + "_error").html(value);
                            });
                        } else {
                            var response = data.msg;
                            if (response && response.length > 0) {
                                for (i = 0; i < response.length; ++i) {
                                    var month_id = response[i].month_id;
                                    var row_id = response[i].id;
                                    appendRow(feetype_id, row_id);
                                }
                            } else {
                                appendRow(0, 0, 0);
                            }

                            $('#chkAdd');

                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown)
                    {
                    }
                });

        e.preventDefault();

    });
});
function appendRow() {
    var value = $('#TextBoxContainer .app').length;    
    var row = "";
   row += '<td class="mailbox-name"><input class="form-control" name="month_id" value="<?php echo set_value('month_id', $month['type']); ?>"/></td>';
    row += '<td class="mailbox-name"><input class="form-control" name="startDate"  value="<?php echo set_value('startDate', $feetype['start_date']); ?>"/></td>';
    row += '<td class="mailbox-name"><input class="form-control" name="endDate" value="<?php echo set_value('startDate', $feetype['end_date']); ?>"/></td>';
    row += '<td class="mailbox-name"><input id="amountCell" name="amountCell" placeholder="" type="text" class="form-control"/></td>';
    row += '<td class="mailbox-name"><input id="penaltyCell" name="penaltyCell" placeholder="" type="text" class="form-control"/></td>';
    $count++;
    row += '</tr>';
     $("#TextBoxContainer").append(row);
}
</script>

0 个答案:

没有答案