Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    30
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Need help with switching variables...

    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:

    <script>
    function addColor(color, chat, text) {
    var revisedMessage;
    var currentMessage = document.chat.elements[text].value;
    revisedMessage = currentMessage+color;
    document.chat.elements[text].value=revisedMessage;
    document.chat.elements[text].focus();
    return;
    }
    </script>

    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?

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Is this what you are trying to do?

    Code:
    <script>
    function colour() {
    	var strColor = document.frm.selColor.value;
    	if( document.selection.type == "Text" ) {
    		var objRange = document.selection.createRange()
    		alert( ":" + strColor + ":" + objRange.text + ":/" + strColor + ":" );
    	}
    	else
    		alert( "No text selected" );
    }
    </script>
    
    <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>
    </select>
    <br><br>
    <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();">
    </form>
    Please note that this is an IE only example.

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    30
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?
    Last edited by thepip3r; 03-22-2005 at 06:31 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •