开发者

Doesn't fade out error message after passing 3 char length

<form id="createtableform" method="post" action="">
  <p>
    Masa ismi :
    <input type="text" name="name" id="tablename" />
  </p>
  <p>
    <input type="submit" name="submit" id="submit" value="submit" />
  </p>
</form>
<div id="error"></div>

$('#tablename').focus();
$('#error').fadeOut(500);
$('#tablename').keyup(function(){
var tablename = $('#tablename').length;

if( tablename <= 3){

$('#error').html('Min 3 characters please');
$('#error').fadeIn(500);
}
if( tablename > 3){
$('#error').fadeOut(500);
}
});

why doesn't this fade out after开发者_如何学运维 i pass 3 chars?

jsfiddle: http://jsfiddle.net/bMJqH/3/


You're getting the length of the array of matched elements instead of the length of the text inside of the field.

Change:

var tablename = $('#tablename').length;

To:

var tablename = $('#tablename').val().length;

Updated fiddle: http://jsfiddle.net/bMJqH/4/

Also, have a look at the API about the length property.


try this:

$('#tablename').keyup(function(){

    var tablename = $('#tablename').val().length;

    if( tablename <= 3){
        $('#error').html('Min 3 characters please');
        $('#error').fadeIn(500);
    } else {
        $('#error').fadeOut(500);
    }

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜