Results 1 to 6 of 6

Thread: Inserting HTML tags into text (javascript)

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Inserting HTML tags into text (javascript)

    I have some buttons on a form which when depressed insert various HTML tags. I want to be able to highlight a certain chunk of text and insert the opening and closing tags either side of the highlighted text.

    Does anyone have any idea how to do this ?

    I'm stuck.
    Thanks in Advance

    Parksie

  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    Where's the 'chunk' located at? Is it in a div or someplace accessible? If not - can you make it be that ?
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    It is in a textbox.

    Parksie

  4. #4
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    ok, try this out

    Code:
    <html>
    
    <head>
    function tagit() {
    var tagdiv=document.getElementById("tagdiv");
    tagdiv.innerHTML="<"+document.myform1.mytag1.value+">";
    }
    </head>
    
    <body>
    
    <form name="myform1">
    <input type="text" name="mytag1" />
    </form>
    <br /><br />
    <div id="tagdiv"></div>
    <br /><br />
    <input type="button" onClick="tagit();" value="Tag it!">
    
    
    </body>
    
    </html>
    dunno if it works, but it should give you an idea on how to do what you want.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  5. #5

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    Interesting.
    I'll mess around with it and see if I can do anything with it but unfortunatly I am no javascript man.

    I did dig this up which is quite interesting :

    http://www.webreference.com/js/column12/index.html

    Parksie

  6. #6
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    this mate?
    Code:
    <script language="javascript">
    function tagit(){
       var t=document.getElementById('tagdiv');
       var s=document.myform1.mytag1.value;
       s=s.replace(/\</gi,"&lt;");
       s=s.replace(/\>/gi,"&gt;");
       t.innerHTML=s;
    }
    </script>
    
    <form name='myform1'>
    <input type=textarea name='mytag1'>
    </form>
    <div id='tagdiv'></div><br><br>
    <input type=button onclick='tagit();' value='tag it!'>
    </form>

Posting Permissions

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



Click Here to Expand Forum to Full Width