|
-
Jul 23rd, 2004, 04:46 AM
#1
Thread Starter
Fanatic Member
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
-
Jul 23rd, 2004, 04:52 AM
#2
Frenzied Member
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.
-
Jul 23rd, 2004, 05:31 AM
#3
Thread Starter
Fanatic Member
-
Jul 23rd, 2004, 05:38 AM
#4
Frenzied Member
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.
-
Jul 23rd, 2004, 05:59 AM
#5
Thread Starter
Fanatic Member
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
-
Jul 23rd, 2004, 09:12 PM
#6
Fanatic Member
this mate?
Code:
<script language="javascript">
function tagit(){
var t=document.getElementById('tagdiv');
var s=document.myform1.mytag1.value;
s=s.replace(/\</gi,"<");
s=s.replace(/\>/gi,">");
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|