首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >填写完所有字段后自动提交表单

填写完所有字段后自动提交表单
EN

Stack Overflow用户
提问于 2013-04-26 10:15:17
回答 2查看 3.3K关注 0票数 0

实际上,我使用条形码扫描仪来输入字段。例如,如果我有3个字段,那就是:

部件条形码:

商品条形码:

串行条形码:

步骤:

  1. 扫描零件条形码文本字段中的零件条形码
  2. 扫描商品条形码文本字段中的商品条形码
  3. 扫描序列条形码文本字段中的连续条形码,扫描后将提交automatically.

代码如下:

代码语言:javascript
复制
Part Barcode <input type="text" name="part_barcode"/>
Item Barcode <input type="text" name="item_barcode"/>
Serial Barcode <input type="text" name="serial_barcode"/>

<input type="submit" value="Submit"/>

因此,问题是,如果所有字段都已填写,如何使自动提交?

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-26 10:25:47

代码语言:javascript
复制
function DoValidate(){
// check your validate here, 
//if all field pass: return true, if not : return false;

//ex: return $('input[name="part_barcode"]).val().length>10;
}

$('input[name="part_barcode"],input[name="item_barcode"],input[name="serial_barcode"]').keypress(function(){
    if(DoValidate()) $('#yourForm').submit();
   //or: $('input[type="submit"]').trigger('click');
});
票数 1
EN

Stack Overflow用户

发布于 2013-04-26 10:39:30

您还没有给我们提供表单的名称,所以我在代码中假设它具有id="formID"属性。在jsfiddle上演示。

HTML:

代码语言:javascript
复制
<label for="part_barcode">Part Barcode</label>
<input type="text" id="part_barcode" class="barcode" name="part_barcode"/>
<label for="item_barcode">Item Barcode</label>
<input type="text" id="item_barcode" class="barcode" name="item_barcode"/>
<label for="serial_barcode">Serial Barcode</label>
<input type="text" id="serial_barcode" class="barcode" name="serial_barcode"/>
<input type="submit" id="submitButton" value="Submit"/>

JavaScript:

代码语言:javascript
复制
var inputs = document.getElementsByClassName('barcode');
for(var i = 0; i < inputs.length; i++)
{
    inputs[i].onblur = function()
    {
        var empty = false;

        for(var j = 0; j < inputs.length; j++)
        {
            if(inputs[j].value == '')
            {
                empty = true;
                break;
            }                
        }

        if(!empty)
            document.getElementById("submitButton").submit();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16227701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档