Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

trying to make buttons for bbcode

Posted on 2008-10-16
7
147 Views
Last Modified: 2010-04-06
i have made by bbcode but now im trying to pull together some puttons to use with the code but i have come accross soem problems,,,

i have 3 areas i cant figure out how to creat buttons for these are:

colour
size
font

i would like to creat a drop down menu with say

red
blue
black
green

and when one of the colours are selected it sets the code in the box as  
[color=red][/color]  

ho do i do this?
0
Comment
Question by:runnerjp
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22731238
I hope this helps you.

Kind regards,

Matthias Vance
<textarea id="txt">
</textarea>
<button onclick="setColor();">Color</button>
<select id="color">
	<option value="red">Red</option>
	<option value="blue">Blue</option>
</select>
<script language="JavaScript">
	function setColor() {
		var color = document.getElementById("color").value;
		var textbox = document.getElementById("txt");
		textbox.value = "[color=" + color + "][/color]";
	}
</script>

Open in new window

0
 

Author Comment

by:runnerjp
ID: 22731986
well im mopre workign on the emphasis of things like

<input type='button' value='CENTER' name='btnUrl' onclick='wrapText(document.getElementById(&#39;inputforum&#39;),&#39;[center]&#39;,&#39;[/center]&#39;);'>

so all i really want is for it to be selected as a drop down...like you do on word ect... plus the above code does not work it just refreshes the page?
0
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22732281
What browser are you using? I tested in IE7/FF/Chrome.

You could use the onChange event of the dropdown box to call that same function with the value that the box currently holds.

Kind regards,

Matthias Vance
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:runnerjp
ID: 22732477
yes that sounds good... are there any websites that i could look at:O
0
 
LVL 8

Accepted Solution

by:
MatthiasVance earned 500 total points
ID: 22732654
I provided some code for you which works exactly like that. It's just an example.

Kind regards,

Matthias Vance
<script language="JavaScript">
	function setColor(color) {
		var textbox = document.getElementById('txt');
		textbox.value = "[color=" + color + "][/color]";
	}
</script>
<textarea id="txt">
</textarea>
<select id="color" onchange="setColor(this.value);">
	<option value="red">Red</option>
	<option value="blue">Blue</option>
</select>

Open in new window

0
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22732667
Or in your code:

function setColor(color) {
wrap(document.getElementById('txt'), "[color=" + color + "]", "[/color]");
}
0
 

Author Comment

by:runnerjp
ID: 22738763
im setting up some bbcode for my forum and i have run into a problem...

you see it works by adding the value in my text box but...

1. you can only select one colour
2. if you write some text then add the colour it deletes all the text??

any way around this
[CODE]
 
function setColor(color) {
                var textbox = document.getElementById('inputforum');
                textbox.value = "[color=" + color + "][/color]";
        }
 
<select id="color" onchange="setColor(this.value);">
      <option value="" selected="selected">Change Color</option>
							<option value="black">Black</option>
							<option value="red">Red</option>
							<option value="yellow">Yellow</option>
							<option value="pink">Pink</option>
							<option value="green">Green</option>
							<option value="orange">Orange</option>
							<option value="purple">Purple</option>
							<option value="blue">Blue</option>
							<option value="beige">Beige</option>
							<option value="brown">Brown</option>
							<option value="teal">Teal</option>
							<option value="navy">Navy</option>
							<option value="maroon">Maroon</option>
							<option value="limeGreen">Lime Green</option>
							<option value="white">White</option>
</select>[/CODE]

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question