Jump to content

BB Code Editor


iShaun

Recommended Posts

Hi, I am making some PHP Software and I am absoloutly horrible with JavaScript. Can someone point me in the direction of a good bb code editor? Keep in mind i DO NOT WANT A WYSIWYG EDITOR! Thats all can find tutorials on. Anyways, could someone give me a basic idea on how to highlight some text, hit a button, and have TEXT entered please? much appreciated.

Link to comment
Share on other sites

Try something like this:

 

HTML:

<textarea name="my_area" id="my-area" cols="60" rows="20"></textarea><br />
<input type="button" name="selection" value="Bold" onclick="makeBold('my-area');" />

 

JavaScript:

function makeBold(id)
{
var el = document.getElementById(id);
if (!el.selectionStart)
{
	if (document.selection.createRange().parentElement().tagName != 'TEXTAREA')
	{
		el.focus();
		return false;
	}
	var r = document.selection.createRange().text;
	document.selection.createRange().text = '<b>' + r + '</b>';
}
else
{
	var txt = el.value;
	var before = txt.substring(0, el.selectionStart);
	var after  = txt.substring(el.selectionEnd);
	var selection = txt.substring(el.selectionStart, el.selectionEnd);

	el.value = before + '[b]' + selection + '[/b]' + after;
}
el.focus();
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.