help with BBCode

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

help with BBCode

Post 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
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply