View Full Version : Need help with switching variables...

03-22-2005, 02:34 AM
I have a chat room that I'm trying to incorporate a clickable color wheel that will input a tag like :red: if the user wants to encode that section of the string in red text, and then if they click it again, it will write :/red: to the screen. I can only get it to do the first using this code in my head:

function addColor(color, chat, text) {
var revisedMessage;
var currentMessage = document.chat.elements[text].value;
revisedMessage = currentMessage+color;

and this code to be the actual clickable portion:

<a href="javascript:void[0];" onClick="addColor(':red:','chat','text');">red</a>

is there a simple way to do this?

03-22-2005, 02:52 PM
Is this what you are trying to do?

function colour() {
var strColor = document.frm.selColor.value;
if( document.selection.type == "Text" ) {
var objRange = document.selection.createRange()
alert( ":" + strColor + ":" + objRange.text + ":/" + strColor + ":" );
alert( "No text selected" );

<form action="" method="post" name="frm" id="frm">
Choose text colour:<br>
<select name="selColor">
<option value="red">red</option>
<option value="blue">blue</option>
<option value="yellow">yellow</option>
<option value="green">green</option>
<textarea name="txtContent" cols="50" rows="8" id="txt"></textarea><br><br>
<input type="button" name="btn" value="Get the new colour string" onclick="colour();">

Please note that this is an IE only example.


03-22-2005, 07:27 PM
No that's not what i'm looking for. I have color'd hyperlinks on a form that when clicked, automatically insert the color in a quasi-BB code format.

i.e. if "red" link is clicked, the the text submission field, a :red: shows up. Then I have PHP code that trades :red: for <font color=#ff0000>.

What I need left is if the red link has been clicked to open up the font tag and a user doesn't want their whole string to be red, maybe just one word, I want them to be able to click the "red" hyperlink again and it insert something like :/red: into the text string so I can tell PHP an easy way to terminate the font string: </font>.

Does that make sense?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum