469,631 Members | 1,736 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Adding text format like bold or italic to the TextArea

hi!
i'm using textarea to type the contents.
inwhich i need to make the text as italic


if i use the following code i'm not getting the italic text instead i'm getting the html tags like <i>text</i> around the text.

how can i rectify these problem.

give me some suggestion.

[HTML] <textarea rows="13" name="messages" cols="65" tabindex="5" style="border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1">

<input type="button" value="&nbsp;I&nbsp;" name="Italic" tabindex="7" style="border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1" onclick="insertItalic()">

[/HTML]



Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. function insertItalic()
  4. {
  5.  
  6.  
  7.  var str = document.selection.createRange().text;
  8. document.compose.messages.focus();
  9. var sel = document.selection.createRange();
  10.  
  11. sel.text=str.italics();
  12.  
  13. return;
  14.  
  15.  
Dec 5 '07 #1
5 18488
hash4sp
55
Hi !

try using css...font-style: italic...for the text..

cheers!
Dec 5 '07 #2
Hi !

try using css...font-style: italic...for the text..

cheers!

thanks for your reply..

I have used css like what u told to me and script also . It will change the italic for the whole textarea.But i couldn't make the particular text as italic. Even I can select a paricular text using selection.createRange() .Anybody please help me..



I have used the following script....

Expand|Select|Wrap|Line Numbers
  1.  
  2. function makeItalic()
  3. {
  4. var s= document.getElementById("it");
  5.  
  6. s.style.fontStyle="italic";
  7. }
  8.  


[HTML] <input type="button" onClick="makeItalic()" value="italic">[/HTML]
Dec 5 '07 #3
mrhoo
428 256MB
Each textarea has one style object.

To style individual elements you have to create them and move the textarea value.
Eg, a p or div element and individually styled spans or inline elements containing the text.
Dec 5 '07 #4
hi!

can u please explain with one example
Dec 6 '07 #5
hash4sp
55
hi!

can u please explain with one example
As mrhoo said, try adding <span style=.....> before & after the text of createrange()....

cheers!
Dec 8 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by gooderthanyou | last post: by
3 posts views Thread by Adam Honek | last post: by
2 posts views Thread by VB Programmer | last post: by
1 post views Thread by cleary1981 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.