romy: javascript - text in textarea selektieren

Beitrag lesen

Hi Olli,

nur: how-to? es muss doch eine lösung geben!

habe es mal ausprobiert und dies hier hat funktioniert:
Kann sein, dass man statt window.getSelection auch direkt auf die Textarea zugreifen kann, habe es nicht probiert.

<schnipp>

<html><head><title>Test</title>
<script type="text/javascript">
<!--
  function selektierterText()
  {
   if (window.getSelection) alert(window.getSelection());
   else if (document.getSelection) alert(document.getSelection());
        else if (document.selection) alert(document.selection.createRange().text);
  }
//-->
</script>
</head><body>
<textarea name="b" cols="20" rows="20"></textarea>
<form>
<input type="button" value="zeigen" onMouseDown="selektierterText();">
</form>
</body></html>

</schnapp>
ciao
romy