Forum Moderators: open

Message Too Old, No Replies

billboard bold issues

Advanced onClick Insert Tag

         

Stuperfied

10:27 am on Feb 23, 2005 (gmt 0)

10+ Year Member



Hello all.
Ive created a page for admins to edit page content. Admins can simply edit the html of a page directly in a textarea. Ive also made buttons as such (<b>, </b>, <u>, </u>, <i>, </i>) and added an onClick behaviour to make them insert the tags directly into the textarea. At present, the tags are simply tacked onto the end of the textarea value.

Can anyone tell me how to have the tags inserted into the position where the cursor is and possibly even replace any text which is selected.

Another possibility is if the selected text is enclosed in open and close tags via onClick.

Any help would be appreciated.

<form name="Content_Edit" method="post" action="content_edit.asp">
<p>
<input type="button" Value="&lt;b&gt;" onClick="this.form.textarea.value=this.form.textarea.value+'&lt;b&gt;'">
<input name="button" type="button" Value="&lt;/b&gt;" onClick="this.form.textarea.value=this.form.textarea.value+'&lt;/b&gt;'">
<input name="button2" type="button" Value="&lt;u&gt;" onClick="this.form.textarea.value=this.form.textarea.value+'&lt;u&gt;'">
<input name="button3" type="button" Value="&lt;/u&gt;" onClick="this.form.textarea.value=this.form.textarea.value+'&lt;/u&gt;'">
<input name="button32" type="button" Value="&lt;i&gt;" onClick="this.form.textarea.value=this.form.textarea.value+'&lt;i&gt;'">
<input name="button33" type="button" Value="&lt;/i&gt;" onClick="this.form.textarea.value=this.form.textarea.value+'&lt;/i&gt;'">
</p>
<p>
<textarea name="textarea" cols="45" rows="15"><% set file = fso.OpenTextFile(strFileName,ForReading) %><% Response.Write replace(file.readall, vbCrlf, "<BR>") %><% file.close %></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
<input name="Reset" type="reset" id="Reset" value="Reset">
</p>
</form>

SpaceFrog

1:24 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



here is a short example you will have to enhance to add more tags but the basics are ther:

<html> 
<head>

<script language="JavaScript">

var choix_balise = new Array(2);
for(i=0;i<2;i++) { choix_balise[i] = false;}

function mk_ajouter(champ, ms1, ms2,x)
{
var tmpstr='';
choix_balise[x]=!choix_balise[x];
tmpstr=(choix_balise[x])?ms1:ms2;

if (document.selection)
{
champ.focus();
sel = document.selection.createRange();
if (sel.text.length == 0)
{
sel.text = tmpstr;
}
else
{
sel.text= tmpstr += sel.text + ms2;
}
}
}

</script>

</head>
<body>
<div align="center">
<form name="form" method="post" action="#">
<input type="button" name="b" value="bold" onClick="mk_ajouter(document.form.champ,'<b>','</b>',1)">
<input type="button" name="u" value="italic" onClick="mk_ajouter(document.form.champ,'<i>','</i>',2)">
<br>
<textarea name="champ" value="" cols="70" rows="10"></textarea>
</form>
</div>
</body>
</html>

Stuperfied

5:20 am on Feb 25, 2005 (gmt 0)

10+ Year Member



Thanks, took me a while to get it working because of silly errors on my part but it works great now.

Thankyou very much for your help.

SpaceFrog

8:15 am on Feb 25, 2005 (gmt 0)

10+ Year Member



Well I must admit that sometimes my codes still withhold silly errors... I just don't take the time to verify them, some of them are not even finished as I often work on more than 10 codes at a time ...
So sorry if sometimes I give falty codes but at least it shows you the principles ...