1

I want to check a textarea input to see if it has at least 10 character otherwise a tooltip notification appears as info. but it does not work

I use twitter bootstrap 3

I dont want to put notification content inside HTML it should be decided by JS only.

http://jsbin.com/iVOgIxO/2/edit

HTML

<form onsubmit="return post_mta();">
    <textarea name="mta" id="" cols="30" rows="10"></textarea>
    <button type="submit">send</button>
</form>

JS

function post_mta()
{
  var ta='textarea[name="mta"]';
  if($(ta).val().length<10)
  {
    $(ta).tooltip({html:'at least 10 characters'});
  }
  return false;
}

1 Answer 1

1

Here is a slightly modified version that will handle the character check:

function post_mta()
{
  $ta = $('textarea[name="mta"]');
  if($ta.val().length<10)
  {
    $ta.val('at least 10 characters'); /* just for testing */
    //$(this).tooltip({html:'at least 10 characters'});

    return false;
  }
}

However, for some reason I couldn't get the Bootstrap tooltip to render. Perhaps it may on your setup.

Sign up to request clarification or add additional context in comments.

1 Comment

seems tooltip does work well only on <a> tags. anyway i'm thinking about using red errors rather than tooltip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.