Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting html tags into a textarea on click of a button 1

Status
Not open for further replies.
Hi,

I was wondering if anyone has a form that does this or knows where I can "borrow" one.

I need to allow users to enter html tags into the text box that they are currently editing. Currently html tags can be added manually but the users of this website are unlikely to know html so I want them to be able to select a word they have typed in the textfield or textarea and click a button, say bold, and it will insert <b> and </b> around the word that they have selected.

Hope this makes sense.

Cheers

Milage
 
Sorry about the book icon. I must have changed it accidentally. It is actually a question as you ahve probably guessed.
 
Is this for on-screen display only, or do you have to submit this form?

If its for on-screen only then you could use CSS, changing the properties of the text-box's text when a button is clicked.
 
here is what i have (doesn't work in netscrap: afaik it doesn't support textRange object.. :( )

<html><head><title>generate your post :)</title>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
var IE=document.all || document.getElementById
var NC=document.layers

function Inserty(){
var prestart,preend,start,end,sel,range,thetext,dvsn,colname,theform,formname,colselname,colsel,effselname,effsel,effname,eff
formname=&quot;myne&quot;
colselname=&quot;colorName&quot;
effselname=&quot;effectName&quot;
theform=document.forms[formname]
colsel=theform[colselname]
effsel=theform[effselname]
colname=colsel.options[colsel.selectedIndex].value
effname=effsel.options[effsel.selectedIndex].text
eff=effsel.options[effsel.selectedIndex].value

dvsn=[&quot;[&quot;,&quot;]&quot;,&quot;[/&quot;]
prestart=&quot;&quot;
preend=&quot;&quot;

if (colname!='none'){
prestart=dvsn[0]+'color '+colname+dvsn[1]
preend=dvsn[2]+'color'+dvsn[1]
}

start=(effname!='color')?prestart+dvsn[0]+eff+dvsn[1]:prestart
end=(effname!='color')?dvsn[2]+eff+dvsn[1]+preend:preend

sel=(IE)?document.selection:(NC)?document.getSelection():null
range=sel.createRange()
thetext=range.text
if (thetext.length){
range.text=start+thetext+end
}}
//-->
</script>
</head>

<body>
<form name=myne>
<textarea name=&quot;txtar&quot; cols=60 rows=14 wrap=virtual>
</textarea><br>
<input type=&quot;button&quot; name=&quot;b1&quot; value=&quot;effect&quot; onclick=&quot;Inserty()&quot;>
<select name=&quot;effectName&quot;>
<option value='b' selected>bold
<option value='i'>italics
<option value='u'>underline
<option value='s'>strike through
<option value='color'>color
</select>
<select name=&quot;colorName&quot;>
<option value='none' selected>None
<option value='green'>Green
<option value='red'>Red
<option value='grey'>Grey
<option value='blue'>Blue
</select>
</form>
</body>
</html>



sometimes, when i wanna *smile* myself i use it for my posts here :)))
Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top