PDA

View Full Version : about bbcode



vividona
Jul 6th, 2009, 09:48 AM
Hi everyone,

I made php function for set and replacing bbcode

now I need to know how can I insert these codes into form fields. As I know this run through javascript

vividona
Jul 6th, 2009, 10:07 AM
I found this but refuse to insert color and size


<script language="javascript" type="text/javascript">

function addText(Text)
{
var obj = document.form.message;
obj.focus();

if (document.selection && document.selection.createRange) // Internet Explorer
{
sel = document.selection.createRange();
if (sel.parentElement() == obj) sel.text = Text;
}

else if (obj != "undefined") // Firefox
{
var longueur = parseInt(obj.textLength);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0,selStart) + Text + obj.value.substring(selEnd,longueur);
}

else obj.value += Text;

obj.focus();
}


function addTags(Tag, fTag)
{
var obj = document.form.message;
obj.focus();

if (document.selection && document.selection.createRange) // Internet Explorer
{
sel = document.selection.createRange();
if (sel.parentElement() == obj) sel.text = Tag + sel.text + fTag;
}

else if (obj != "undefined") // Firefox
{
var longueur = parseInt(obj.textLength);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0,selStart) + Tag + obj.value.substring(selStart,selEnd) + fTag + obj.value.substring(selEnd,longueur);
}

else obj.value += Tag + fTag;

obj.focus();
}

</script>



// In example, a part of the form

<form method="post" name="form" action="...">

<a title="Bold : [B ][/B ]" onmousedown="addTags('[B ]','[/B ]')" style="background-color:#F7F7F7; font-size:10pt; border: outset white 1px;">&nbsp;<b>B</b>&nbsp;</a>

<img src="images/smilies/smile.gif" title="[:) ]" onmousedown="addText('[:) ]')">

<textarea wrap="VIRTUAL" name="message" cols="50" rows="10"></textarea>

</form>