0

I have a text area in form. When some text from text area is being selected, I have to enable a button. How can I do that?

3 Answers 3

3

If you want to do something when text is selected, take a look at the .select() jQuery event. Then you can enable/disable the button however you like.

Example from the jQuery page:

<!DOCTYPE html>
<html>
<head>
  <style>
  p { color:blue; }
  div { color:red; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <p>

    Click and drag the mouse to select text in the inputs.
  </p>
  <input type="text" value="Some text" />
  <input type="text" value="to test on" />

  <div></div>
<script>
    $(":input").select( function () { 
      $("div").text("Something was selected").show().fadeOut(1000); 
    });
</script>

</body>
</html>
2

You can use the onfocus event of textarea for this kind of job.

1

This can only be done with Javascript, because when some text is being selected, that is only on the client side. And with jQuery show(); hide(); (CSS) it should be fairly easy.

1
  • what i was not sure is which event to use to trigger when text is selected in text area Commented Oct 6, 2011 at 15:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.