2013-04-26 65 views
0

其實我使用條碼掃描器輸入字段。 實施例,如果我有3場,這就是:完成全部字段後自動提交表格

部分條碼:
物品條形碼:
串行條碼:

的步驟:在部分條碼文本字段
1.掃描條碼部分條形碼
2.掃描項目條碼文本欄中項目條碼的條碼
3.掃描串行條碼文本欄中串行條碼的條碼,掃描完成後自動提交。

下面是代碼:

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"/> 

所以現在的問題是,如何使自動提交,如果所有字段已經被填補?

謝謝。

+0

嗨,問題是:如何讓在所有領域已經充滿自動提交? – 2013-04-26 02:20:08

+0

當輸入被更改並且沒有任何內容爲空時,是否嘗試過執行'$('form')。submit()'? – viclim 2013-04-26 02:22:48

+0

我們的倉庫有類似的問題 - 如果我正確記得,我們只是在最後一個條形碼的末尾編碼回車。你是否爲第3步創建了條形碼?如果是這樣,那可能是您的一個選擇。 – 2013-04-26 02:39:35

回答

1
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'); 
}); 
+0

你怎麼知道OP使用jQuery? – j08691 2013-04-26 02:31:53

+0

是的,真的沒有必要的jQuery。 – SimonDever 2013-04-26 02:43:57

0

你沒有給我們你的表格名稱,所以我在我的代碼中假設它具有屬性id="formID"。演示jsfiddle

HTML:

<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:

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(); 
    } 
}