Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Clicking on a button or link adds something to textarea

Featured Replies

Hello everyone,

I am currently developing a forum and we decided to use a html editor to post threads at first.

We have changed our minds and decided that we only want to allow BB code.

So we have bb codes for like bold, italic, new line. horizontal line etc.

 

So we want to add something above the text area. Like a button with a B I or underscored U on the top of this html editor.

And when the user clicks on the B for example, it should add to the textarea. I think this could be done with javascript?

My textarea on the edit thread page:

	<a href="#"">Bold </a> // So when the user clicks this, it should add [b][/b] to the end of the textarea below without changing the content that is already in the textarea.
	<textarea id="editor1" name="editor1EDIT" rows="10" cols="80">'.$getthethreadcontent.'</textarea>
	

 

Im really a noob at javascript so any advice on how to do this would be helpful. If there are any other methods then javascript i am willing to hear it. 

I'd be inclined to use a ready-made solution. It's going to perform better and be much easier. I've used SCEditor in the past. It's fairly decent: 

https://www.sceditor.com/

It comes with loads of options (buttons on the toolbar). If you only want the ones listed above, check out this page on the documentation to limit the options: 

https://www.sceditor.com/documentation/options/

 

 

Edited by Fee

  • Author

Edit:

About SCEditor...

I currently am trying it out and sofar its exactly what i need except..

http://losangeles-roleplay.org/example.html

When you type test. Press enter for new line it doesn't add a [br]? Shouldn't it do that automatically?

Thanks. So is there also something to process bb code?

Currently doing it like this:

	// bb to html
	$getthethreadcontent = htmlspecialchars($getthethreadcontent);
$getthethreadcontent = str_replace('[url=&quot;','<a href="', $getthethreadcontent);
$getthethreadcontent = str_replace('&quot;]','">', $getthethreadcontent);
$getthethreadcontent = str_replace('[/url]','</a>', $getthethreadcontent);
$getthethreadcontent = str_replace('[br]','</br>', $getthethreadcontent);
	//html to bb
	$getthethreadcontent = htmlspecialchars($getthethreadcontent);
$getthethreadcontent = str_replace('&lt;a href=&quot;','[url="', $getthethreadcontent);
$getthethreadcontent = str_replace('&quot;&gt;','"]', $getthethreadcontent);
$getthethreadcontent = str_replace('&lt;/a&gt;','[/url]', $getthethreadcontent);
$getthethreadcontent = str_replace('&lt;/br&gt;','[br]', $getthethreadcontent);
	

Edited by ChubbyKakert

Cool was the only thing I could spot that looked different and you had mentioned the line break issue. I remember an old project that had two different ways stuff had been saved, ended up with a work around swapping with actual characters so we could output both <p> and <br> correctly.

function revrn($var) { return str_replace(array(chr(13), chr(10)), array('\r', '\n'), $var); }

 

Edited by BrowserBugs

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.