PDA

Click to See Complete Forum and Search --> : Inserting HTML tags into text (javascript)


venerable bede
Jul 23rd, 2004, 04:46 AM
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

vbNeo
Jul 23rd, 2004, 04:52 AM
Where's the 'chunk' located at? Is it in a div or someplace accessible? If not - can you make it be that ?

venerable bede
Jul 23rd, 2004, 05:31 AM
It is in a textbox.

vbNeo
Jul 23rd, 2004, 05:38 AM
ok, try this out


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

venerable bede
Jul 23rd, 2004, 05:59 AM
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

brown monkey
Jul 23rd, 2004, 09:12 PM
this mate?

<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>