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 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Manipulating a forms textarea

    Hi,

    I am trying to create a button on my form that when pressed, will add a certain html tag to the beginning and end of the selected string. Same as what is used in this textarea where if you select a certain string and click the above Bold icon, it will put the tags in.

    Any help apreciated. Thanks.

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this:

    Code:
    <html>
    <head>
    <title></title>
    
    <script language="Javascript">
    <!--
    function addTag()
    {
    	var startTag = "<b>";
    	var endTag = "</b>";
    	var content = document.myform.content.value;
    	document.myform.content.value = startTag + content + endTag; 	
    }
    //-->
    </script>
    </head>
    
    <body>
    
    <form name="myform">
    <p><textarea name="content" rows="5" cols="35" wrap="virtual"></textarea></p>
    <p><input type="button" name="btnAddTag" value="Add Tag" onClick="addTag()"></p>
    </form>
    
    </body>
    </html>

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for that but doing this encapsulates the whole textarea with the tags and not just the selected text. Is there a way we can add the tags to only the selected text?

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


  •  

    Posting Permissions

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