Auto Submit Form

by MrSaints

HTML

<p>
    <form id="customForm">
        <h1>Auto Submit (change())</h1>
        <label for="custom1">Custom Value</label> 
        <input type="text" name="custom" id="custom1" value="">
        <button type="submit">Submit</button>
    </form>
</p>

<p>
    <form id="customForm">
        <h1>Auto Submit (keyup())</h1>
        <label for="custom2">Custom Value</label> 
        <input type="text" name="custom" id="custom2" value="">
        <button type="submit">Submit</button>
    </form>
</p>

JavaScript

// jQuery Form Events ( change() )
$('#custom1').change(function() {
    if ($(this).val().length > 5) {
        console.log('Custom value length is more than 5');
        alert('Submit!');
        // Submit Form
        // $('#customForm').submit();
    }
});

// jQuery Events ( keyup() )
$('#custom2').keyup(function() {
    if ($(this).val().length > 5) {
        console.log('Custom value length is more than 5');
        alert('Submit!');
        // Submit Form
        // $('#customForm').submit();
    }
});