Adding text format like bold or italic to the TextArea

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thirunavukarasu
    New Member
    • Dec 2007
    • 3

    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="insert Italic()">

    [/HTML]



    Code:
     
    
    function insertItalic()
    {
    
     
     var str = document.selection.createRange().text;
    document.compose.messages.focus();
    var sel = document.selection.createRange();
    
    sel.text=str.italics();
    
    return;
  • hash4sp
    New Member
    • Aug 2007
    • 55

    #2
    Hi !

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

    cheers!

    Comment

    • Thirunavukarasu
      New Member
      • Dec 2007
      • 3

      #3
      Originally posted by hash4sp
      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.creat eRange() .Anybody please help me..



      I have used the following script....

      Code:
      function makeItalic()
      {
      var s= document.getElementById("it");
       
      s.style.fontStyle="italic";
      }


      [HTML] <input type="button" onClick="makeIt alic()" value="italic">[/HTML]

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        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.

        Comment

        • Thirunavukarasu
          New Member
          • Dec 2007
          • 3

          #5
          hi!

          can u please explain with one example

          Comment

          • hash4sp
            New Member
            • Aug 2007
            • 55

            #6
            Originally posted by Thirunavukarasu
            hi!

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

            cheers!

            Comment

            Working...