2017-03-15 76 views
0

我有一個應用程序,用戶掃描條形碼並提交表單。麻煩的是,掃描儀偶爾會出現雙重掃描,所以或者XXX預計值會是XXXXXX,然後表單提交,或者表單快速連續提交兩次。我想以某種方式添加一些暫停條件,以防止敏感的雙重掃描。有任何想法嗎 ?敏感掃描儀問題。防止雙重掃描

目前代碼

 <script> 
     function validateForm(form) { //This is the name of the function 

     if (form.wonumber.value == "OP") { //This checks to make sure the field is not empty 
     alert("Cant Submit."); //Informs user of empty field 
     form.wonumber.value = "" 
     return false; //This prevents the form from being submitted 
     } 
     return true 
     } 
     </SCRIPT> 

    <form action="outer.asp" method="post" name="form100" id="form100" onSubmit="return validateForm(this)"> 
    <div align="center"> 
    <span class="style1 style4 style8"> 
    Scan Parts into Outer <%=request.querystring("id")%>;</span> 
    <p class="style1 style2"> 
    <input name="wonumber" type="text" id="wonumber" style="height:80px;font-size:50pt;" onChange="return validateForm(this)" size="7"> 
    </p> 
    <p class="style1 style10"><%=description1%>&nbsp;<span class="style1 style2 style10"> 
    </form> 
+0

我不認爲你提供的代碼片段告訴整個故事。你會編輯你的原始帖子並插入整個代碼嗎? –

+0

更新了原始文章以包含整個表單代碼。 – Emma

+0

如果您的閱讀器中的字符數超過最大值,是否可以簡單地清除表單? –

回答

0

你OP有很多的問題。我爲這個例子所做的事情是清理你的標記,刪除那些沒有意義的東西,並且寫一些事件處理程序,這會使你的<input>在第一次更改後變爲只讀。我相信這會起作用,因爲我認爲掃描儀就像鍵盤一樣。如果它不起作用,請告訴我。

<!doctype html> 
<html> 
    <head> 
     <script type="text/javascript"> 
      function validateForm(form) { 
       if (form.wonumber.value == "OP") { 
        alert("Cant Submit."); 
        form.wonumber.value = ""; 
        return false; 
       } 
       return true; 
      } 
     </script> 
    </head> 
    <body> 
     <form action="outer.asp" method="post" name="form100" id="form100" onSubmit="return validateForm(this)"> 
      <span class="style1 style4 style8">Scan Parts into Outer <%=request.querystring("id")%>;</span> 
      <input name="wonumber" type="text" id="wonumber" style="height:80px;font-size:50pt;" size="7" onchange="this.readOnly=true"> 
      <p><%=description1%></p>    
      <button type="button" onclick="form.wonumber.value='carrot'">Carrot</button><br> 
      <button type="reset" onclick="form.wonumber.readOnly=false">Reset</button> 
     </form> 
    </body> 
</html>