admin管理员组文章数量:1414621
I am trying to automatically submit a form after scanning a barcode. The number I scan is always 16 digits long.
<form id="Form" action="action.php" method="post">
<input id="here" maxlength="16" placeholder="scan..." type="text" tabindex="1" required autofocus>
<input id="subHere" type="submit">
</form>
<script>
$('#here').keyup(function(){
if(this.value.length ==16){
$('#subHere').click();
}
});
</script>
The restriction of entering 16 digits is working but my form is not automatically submitting after entering the 16 digits.
I also want to clear the form after submitting, so I can scan the next barcode. Do you have any suggestions?
I am trying to automatically submit a form after scanning a barcode. The number I scan is always 16 digits long.
<form id="Form" action="action.php" method="post">
<input id="here" maxlength="16" placeholder="scan..." type="text" tabindex="1" required autofocus>
<input id="subHere" type="submit">
</form>
<script>
$('#here').keyup(function(){
if(this.value.length ==16){
$('#subHere').click();
}
});
</script>
The restriction of entering 16 digits is working but my form is not automatically submitting after entering the 16 digits.
I also want to clear the form after submitting, so I can scan the next barcode. Do you have any suggestions?
Share Improve this question edited Sep 4, 2018 at 7:54 nixfuerdiecharts asked Sep 3, 2018 at 8:00 nixfuerdiechartsnixfuerdiecharts 3836 silver badges16 bronze badges 10-
2
Is that all of your
<form>
? It has noaction
and I don't see a 'click` event being set, so it won't submit anywhere. – peeebeee Commented Sep 3, 2018 at 8:07 - Normaly Barcord machin facilitated to "press enter" after scan. Didn't you try to do with that feture? – Udara Kasun Commented Sep 3, 2018 at 8:25
- my barcode scanner is acting like it is a keyboard, I've tried touse it this way but I do not have this feature – nixfuerdiecharts Commented Sep 3, 2018 at 8:29
- You are currently sending your form to # which does not do anything. Have you build some code that handles the form after submitting? – Granny Commented Sep 3, 2018 at 8:38
- 1 Working here – Fr0zenFyr Commented Sep 3, 2018 at 9:24
2 Answers
Reset to default 3Thanks to Fr0zenFyr it is working now:
<form id="Form" action="./js/filehandling.js" method="post">
<input id="here" maxlength="16" placeholder="scan..." type="text" tabindex="1" required autofocus>
<input id="subHere" type="submit">
</form>
<script src="https://code.jquery./jquery-2.2.4.js"></script>
<script>
$('#here').keyup(function(){
if(this.value.length ==16){
$('#subHere').click();
}
});
</script>
after entering 16 digits, it automatically submits the form
Another way would be :
<script>
$("#input_field").keyup(function() {
if ($(this).val().length >= 16)
$('#form').submit();
})
</script>
本文标签: javascriptAutomatically submitting a HTML form after scanning a barcodeStack Overflow
版权声明:本文标题:javascript - Automatically submitting a HTML form after scanning a barcode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745183937a2646593.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论