HTML Question

Auto Submit When Character reaches a Particular Number in a form isn't Working

This Code Works but when i copy and paste into it, it doesn't submit.

<script src="jquery-3.2.1.min.js"></script>

<form id="Form" action="pro_add_invoice.cfm" method="post">
<input id="here"name="htno" type="text" value="" />&nbsp;
<input id="subHere" type="submit" value="Submit" />
</form>

<script>
$('#here').keyup(function(){
if(this.value.length ==10){
$('#Form').submit();
}
});
</script>

wlh wlh
Answer Source

I'm assuming you just want to submit the form after ten characters are entered. You can use $().submit() instead and pass in the id of the form.

<form id="Form" action="sell.cfm" method="post">
    <input id="here"name="htno" type="text" value="" />&nbsp;
    <input id="subHere" type="submit" value="Submit"  />
</form>

<script>
    //$('#here').keyup(function(){
    //    if(this.value.length ==10){
    //      $('#Form').submit();
    //    }
    //});

    var input = document.querySelector('#here');
    input.addEventListener('keyup', checkLength);
    function checkLength(e){
        if(e.target.value.length===10){
            document.forms["Form"].submit();
        }
    }

</script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download