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

前端 未结 2 1853
被撕碎了的回忆
被撕碎了的回忆 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:46

    Here is the way I would approach this. This also takes into account the user copying and pasting into the input area.

    Jsfiddle -> http://jsfiddle.net/PgzrU/4/

    Code below:

    var max = 15;
    $('input').change(function(e)
    {  
      if ($(this).val().length > max) { alert('form fired') }
    }).keyup(function(e)
    {  
      if ($(this).val().length > max) { alert('form fired') }
    });​
    

提交回复
热议问题