dpjhq00684 2019-08-09 03:57
浏览 27
已采纳

错误填写后如何清理表格?

I have a filling form, when user enter № of invoice, for example IN-111111/11, so in the next form shows the amount, here the photo of successful check, here the photo of unsuccessful check

So in my case, when user enter IN-111111/11, it returns amount 10, and if i change the № of invoice, amount 10 still remains in the second form. How to automatically clean the second form, if user enter the wrong № of invoice?

html code of form:

<label class="label2 invoice"><?php echo _("№ of invoice");?></label>
<input class=" field only-numeric input1 invoice" type="text" name="invoice" value="<?php ?>"/>

<p class="field-set__message invoice-note" style="display: none">Loading</p>
<p class="field-set__message invoice-errnote" style="display: none; color: red"> Please check the correctness</p>

<label class="label2"><?php echo _("Amount(Euro)");?></label>
<input class="field only-numeric input1" type="text" name="order[calcSum]" id="summ" value="<?php echo htmlspecialchars($order->getCalcSum()); ?>"/>

ajax code, how to connect to api:

<script>
    $(document).on('change', '.invoice', '.sum',  function() {
        var loading = $('.invoice-note'),
            _this = $(this),
            err = $('.invoice-errnote');

        err.hide();

        if(_this.val().length > 3) {
            $.ajax({
                url: 'engine/ajax/invoice.php',
                type: 'POST',
                dataType: 'JSON',
                data: {
                    action: 'invoice',
                    invoice: _this.val()
                },
                beforeSend: function() {
                    loading.show();
                },
                success: function(data) {
                    if(data.error) {
                        _this.css('border', '1px solid red');
                        err.show();                     
                    } else {
                        _this.css('border', '1px solid green');
                        $('#summ').val(data.summ);
                    }
                    loading.hide();
                }
            });
        }
    });

    $.ajax({
        url:'engine/ajax/invoice.php',
        type:'POST',
        dataType: 'JSON',
        data:{
            action:'sum',
        }
    })
  • 写回答

1条回答 默认 最新

  • doulou1970 2019-08-09 04:28
    关注

    You can try this method:

    $('#myForm').trigger("reset");
    

    or this way answered other here Resetting a multi-stage form with jQuery

    function resetForm($form) {
        $form.find('input:text, input:password, input:file, select, textarea').val('');
        $form.find('input:radio, input:checkbox')
             .removeAttr('checked').removeAttr('selected');
    }
    
    // to call, use:
    resetForm($('#myform')); // by id, recommended
    resetForm($('form[name=myName]')); // by name
    

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用