Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Formatting text in a text box ? (bold/italic/underline etc)

    Ive looked around with limited success, just wondering if someone could direct me to a tutorial, give some advice or give me some sample code on how one would go about formatting text in a text box.

    For example, i need to be able to format 'selected text' in a text box to make it bold/italic etc.

    Thanks in advance.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,513
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function CngFont(obj,prop,assign){
     obj.style[prop]=assign;
    }
    //-->
    </script></head>
    
    <body>
    <input value="Some Text" style="font-weight:bold;" onclick="CngFont(this,'fontStyle','italic');" >
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks...

    If I had a textbox, is it possible to apply the formatting to a selected text ?
    i.e. select certain text, click eg italic.

    thanks

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Comment Retracted
    Last edited by mildlyincoheren; 05-02-2006 at 12:53 PM.

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Not really. First at all, there are at least 3 ways to capture the selection, according to the browser's type

    window.getSelection() // Moz, Safari
    document.getSelection// Moz, IE 5 for MAC
    document.selection.createRange().text// IE 5+ for Win

    (well, the object which supports the methods might be the text box, at least in IE, not the document or the window - not test in the rest)

    But the main problem is, if I understood well, that khorask wants to "select" a part of the text which is a text box and change it's style, which , as far as I know - I might be wrong - but I think it is impossible, as you may change only the style of the whole text in text box, but you may not isolate a part of it (as you may not insert a <span> object inside the box's value).
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    New to the CF scene
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is old but I will add to the thread.

    You cannot do this with the textbox. Rather you can use javascript to replace the textbox/area with an editable iframe and add more js to handle the events.

    I would suggest using something like www.wymeditor.org or open wysiwyg from openwebware.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •