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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745183938a4615546.html
评论列表(0条)