Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Changing a textarea's selection.


Message #1 by "Chris Cote" <cotec@s...> on Mon, 28 Jan 2002 15:15:26
Hi chris

I dont know if this is what you need

its  a 'scaled down' version of allan's excellent example and i only looked
at it with ie6.

It will render HTML tags around the stuff you've selected.
i guess if you want to implement this in a real app you need to validate
your html somehow to prevent the users from creating overlapping tags etc.

here it comes:

<html>
<head>
<script>
function makeBold()
{
 var oSelection = document.selection.createRange( );
 if(oSelection.text)
 {
  oSelection.text = '<b>' + oSelection.text + '</b>';
 }
}
</script>
<title> New Document </title>
</head>

<body>
<button onClick=makeBold()>Bold</button>
<b>
<textarea name="someArea" cols="100" rows="3">This is some text in a
textarea</textarea>
</form>
</body>
</html>

hope this helps johannes

----- Original Message -----
From: "Chris Cote" <cotec@s...>
To: "javascript" <javascript@p...>
Sent: Thursday, January 31, 2002 15:11
Subject: [javascript] Re: Changing a textarea's selection.


> Well, Allan, this is close to what I want.  What I want is a text box
> (textarea) that users enter text into.  When they click on one of the
> buttons, instead of making the text bold, italics, etc. I want to add the
> html tags before and after the text they highlight.
>   For example, when someone types text into the Message: text box in the
> post a message page.  If someone clicks on the bold button, then the text
> that was highlighted would then be surrounded by <b></b> in the textarea.
>
> So if I highlighted Allan in this message, I would get <b>Allan</b> in the
> textarea, (hopefully it won't give the formatted version, with the Allan
> between the bold tags.
>
> Chris
>
> PS. It's not absolutely essential that I get this ability in.  What was
> needed "ASAP" was an answer about whether or not it could actually be
done.
$subst('Email.Unsub').
>


  Return to Index