【问题标题】:How to make user choose one item in invoice and don't choose the same item again in codeigniter如何让用户在发票中选择一项并且不要在codeigniter中再次选择相同的项目
【发布时间】:2018-01-05 15:04:59
【问题描述】:

我正在制作发票页面,用户从下拉列表菜单中选择他/她的项目,但用户可以在每个下拉列表中选择相同产品的问题,如果他从任何下拉菜单中选择产品,我想要再次选择它。

这是我的看法

    <?php include_once('header_v.php');?>
    <?php
    include_once ('menu_v.php');
    ?>

    <!-- Page Content -->
    <div id="page-wrapper">
        <div class="container-fluid">

            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">Invoice</h1>
                </div>
            </div>
            <?php if($this->session->flashdata('done')): ?>
                <div class="alert alert-success">
                    <strong>Success!</strong> <?php echo $this->session->flashdata('done'); ?>
                </div>
            <?php endif;?>
            <?php if($this->session->flashdata('error')): ?>
                <div class="alert alert-warning">
                    <strong>Warning!</strong> <?php echo $this->session->flashdata('error'); ?>
                </div>
            <?php endif;?>
            <!-- ... Your content goes here ... -->

            <?php $form=array('id'=>'myform');?>
        <?php echo form_open('Order/submit',$form);?>
            <div class="panel panel-default">
                <div class="panel-heading">Customer Details</div>
                <div class="panel-body">
                    <div class="col-xs-3">
                            <select class="selectpicker" data-show-subtext="true" data-live-search="true" name="customer_name">
                                <?php foreach ($customerdata as $c):
                                    echo "<option  value ='$c->c_id'>" . $c->c_name . "</option>";
                                endforeach;
                                ?>
                            </select>
                    </div>
                    <div class="col-xs-3">
                            <input type="text" class="form-control" name="invoice_number"  placeholder="Invoice Number"/>
                    </div>
                    <div class="col-xs-3">
                            <input type="text" class="form-control" name="branch"  placeholder="Branch"/>
                    </div>
                    <div class="col-xs-3">
                            <select class="selectpicker" data-show-subtext="true" data-live-search="true" name="payment_term">
                                <option value="cash">Cash</option>
                                <option value="bank">Bank</option>
                                <option value="other">Other</option>
                            </select>
                    </div>
                </div><!--customer panel-Body-->
                <div class="panel-heading">Invoice Details
                </div>

                <div class="panel-body">

                    <div id="education_fields">


                    <div class="col-sm-3 nopadding">
                        <div class="form-group">
                            <select class="selectpicker" data-show-subtext="true" data-live-search="true" name="select_product[]">
                                <option></option>
                                <?php
                                foreach($order as $row):
                                    echo"<option data-price='$row->p_price' data-qty='$row->s_p_qty' value ='$row->s_p_id'>".$row->s_p_name. "</option>";
                                endforeach;
                                ?>
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-3 nopadding">
                        <div class="form-group">
                            <input type="text" class="form-control qty" onkeypress="return event.charCode >= 48 && event.charCode <= 57;set_qty()" name="qty[]" value="" placeholder="Quantity">
                        </div>
                    </div>
                    <div class="col-sm-3 nopadding">
                        <div class="form-group">
                            <input type="text" class="form-control price"  name="price[]" value="" placeholder="Price"  readonly>
                        </div>
                    </div>

                    <div class="col-sm-3 nopadding">
                        <div class="form-group">
                            <div class="input-group">
                                    <input type="text" class="form-control total"  name="total[]" value="" placeholder="Total" readonly >
                                <div class="input-group-btn">
                                    <button class="btn btn-success" type="button"  onclick="education_fields();"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="clear"></div>
                    </div>

                </div>
                <div class="panel-footer"><small>Press <span class="glyphicon glyphicon-plus gs"></span> to add another product field :)</small>, <small>Press <span class="glyphicon glyphicon-minus gs"></span> to remove the last product :)</small></div>
            </div>
            <button type="submit" class="btn btn-primary center-block">Order Now </button>
        <?php echo form_close();?>
        </div>
    </div>

</div>

<script>

    var room = 0;
    function education_fields() {

        room++;
        var objTo = document.getElementById('education_fields');
        var divtest = document.createElement("div");
        divtest.setAttribute("class", "form-group removeclass"+room);
        var rdiv = 'removeclass'+room;
        var medo='<div class="col-sm-3 nopadding"><div class="form-group"><select class="selectpicker" data-show-subtext="true" data-live-search="true" name="select_product[]"><option></option><?php  foreach($order as $row){ ?><option data-price="<?php echo$row->p_price;?>"  value ="<?php echo $row->s_p_id; ?>"><?php echo $row->s_p_name; ?></option><?php }  ?></select></div></div><div class="col-sm-3 nopadding"><div class="form-group"> <input type="text" class="form-control"  name="qty[]" value="" placeholder="Quantity"></div></div><div class="col-sm-3 nopadding"><div class="form-group"> <input type="text" class="form-control price"   name="price[]" value="" placeholder="Price"  readonly ></div></div><div class="col-sm-3 nopadding"><div class="form-group"><div class="input-group"> <input type="text"  class="form-control total"  name="total[]" placeholder="Total" readonly /><div class="input-group-btn"> <button class="btn btn-danger" type="button" onclick="remove_education_fields('+ room +');"> <span class="glyphicon glyphicon-minus" aria-hidden="true"></span> </button></div></div></div></div><div class="clear"></div>';

        divtest.innerHTML = medo;
        objTo.appendChild(divtest);
        $('select').selectpicker();
    }
    function remove_education_fields(rid) {
        $('.removeclass'+rid).remove();
    }
</script>
<script> // dodal area 
$(document).on('mouseout','.price',function(){
  var quantity  = $(this).parent().parent().prev().find('input[type="text"]').val();
  var price     = $(this).val();
  if(quantity !=='' && price !==''){
    $(this).parent().parent().next().find('input[type="text"]').val(parseInt(quantity) * parseInt(price));
  }
});

$(document).on('mouseout','input[placeholder="Quantity"]',function(){
  var price     = $(this).parent().parent().next().find('input[type="text"]').val();
  var quantity  = $(this).val();
  if(quantity !=='' && price !==''){
    $(this).parent().parent().next().next().find('input[type="text"]').val(parseInt(quantity) * parseInt(price));
  }
});

</script>
<script>
    function set_price( slc ) {
        var price = slc.find(':selected').attr('data-price');
        slc.parent().parent().next().next().find('.price').val(price);
    }
    $('#education_fields').on('change','select.selectpicker',function(){
        set_price( $(this) );
    });

</script>


<script src="<?php echo base_url();?>js/bootstrap-select.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="<?php echo base_url();?>js/bootstrap.min.js"></script>

<!-- Metis Menu Plugin JavaScript -->
<script src="<?php echo base_url();?>js/metisMenu.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="<?php echo base_url();?>js/startmin.js"></script>

</body>
</html>

如果无法在 PHP 中执行此操作,例如发现重复值,则进行求和并将其作为一行插入。

【问题讨论】:

    标签: jquery codeigniter


    【解决方案1】:

    如果您只想阻止用户进入前端,您可以为每个选定的项目设置 data-id 属性,如果用户单击要添加到列表的项目,您可以搜索所有具有 data-id 条件的项目并在重复时阻止它.

    【讨论】:

    • 你能举个例子吗?
    • 我想阻止用户在下一个下拉列表菜单中再次显示该项目,如果他点击它,我有一个想法在提交按钮中起作用,检查他是否选择了重复的项目
    • 我找到了这个例子,但不适用于我的脚本jsfiddle.net/jFMhP
    【解决方案2】:

    使用 数据属性 是个好主意,但我分享了我想验证选择控件时使用的解决方案,该选项已存在于另一个前一行选择中。实际上我使用 jquery.repeater 插件而不是 HTML 表或 DataTable。

    function selectValueDuplicated(selector, value) {
        var checker = {};
        $(selector).each(function(index, element) {
            console.log('index:', index);
            console.log('element:', element);
    
            var selection = $(this).val();
            if ( checker[selection] ) {
                alert("Duplicate(s) detected!");
                return false;
            } else {
                checker[selection] = true;
            }
        });
        console.log(checker);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-06-14
      • 1970-01-01
      • 2020-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-10
      相关资源
      最近更新 更多