Page 1 of 1

help with BBCode

Posted: Mon Sep 19, 2005 4:35 pm
by Smackie
I was wondering how i could make it where when someone would click on one of the emoticons it would show up like :test: in the text field? i have all the bbcoding but i dont know how they make it place in the field without accually typing it in?

can someone help me Please
Thank you
Smackie

Posted: Mon Sep 19, 2005 5:02 pm
by raghavan20
i will provide you the logic.

you have to wrap images in <a> and for the onclick event provide relevant javascript call
for ex:

Code: Select all

addemoticon("test:");
and using javascript, add the value got by the function into the textarea/ div using dhtml.

later you can parse the GET or POST variable in PHP and replace those values with <img> tags.

Posted: Mon Sep 19, 2005 9:12 pm
by s.dot

Code: Select all

<script language="javascript" type="text/javascript">
<!--
function insertSmilie(text) {
  text = '' + text + '';
  if (document.frmPost.txtPost.createTextRange && document.frmPost.txtPost.caretPos) {
    var caretPos = document.frmPost.txtPost.caretPos;
    caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
    document.frmPost.txtPost.focus();
  } else {
    document.frmPost.txtPost.value  += text;
    document.frmPost.txtPost.focus();
  }
}
//-->
</script>
<form id="frmPost">
<input type="text" name="name" id="txtPost">
<input type="submit" value="submit">
</form>

Smiley Face: <a href="#" onClick="insertSmiley(':text:');">smiley</a>