How to auto-submit form after entering text of certain length into input field

前端 未结 2 1852
被撕碎了的回忆
被撕碎了的回忆 2021-01-16 12:20

I am looking for an auto-submit function for my form which should submit it once user enters text of certain length (lets say 15 chars) into an input field.

Is ther

2条回答
  •  盖世英雄少女心
    2021-01-16 12:34

    Instead of checking for length of text in input field at particular interval, lets attach keyup event handler to the text field. Every time the keyup event is fired, we'll check if the length exceeds 15. If it does then we'll submit the form with .submit() API.

    $('yourTextBoxSelector').on("change paste keyup", function(){
        if($(this).val().length >15){
            $('yourFormSelector').submit()
        }
    });
    

    UPDATE : jQuery has an event paste. You can use it...

提交回复
热议问题