jquery - check length of input field?
Posted
by KnockKnockWhosThere
on Stack Overflow
See other posts from Stack Overflow
or by KnockKnockWhosThere
Published on 2010-04-24T01:40:53Z
Indexed on
2010/04/24
1:43 UTC
Read the original article
Hit count: 960
The code below is intended to enable the submit button once the user clicks in the textarea field. It works, but I'm trying to also make it so that it's only enabled if there's at least one character in the field. I tried wrapping it in:
if($(this).val().length > 1)
{
}
But, that didn't seem to work... Any ideas?
$("#fbss").focus(function(){
$(this).select();
if($(this).val()=="Default text") {
$(this).val("");
$("input[id=fbss-submit]").removeClass();
$("input[id=fbss-submit]").attr('disabled',false);
$("input[id= fbss-submit]").attr('class','.enableSubmit');
if($('.charsRemaining')) {
$('.charsRemaining').remove();
$("textarea[id=fbss]").maxlength({
maxCharacters: 190,
status: true,
statusClass: 'charsRemaining',
statusText: 'characters left',
notificationClass: 'notification',
showAlert: false,
alertText: 'You have exceeded the maximum amount of characters',
slider: false
});
}
});
© Stack Overflow or respective owner