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 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    30
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Javascript function help: trying to get a variable to change if it's set

    Overall Purpose: I want a clickable button that inputs preformatted text into a submission field and the button should know whether it's open or closed...

    Working Now: On the click of a hyperlink, I can get the text to display in the submission field like I want.

    Problem: If the button has already been clicked and it's clicked again, the same information shows instead of adding a close tag to it.

    This works:

    in the head
    Code:
    <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>
    in the body
    Code:
    <a href="javascript:void[0];" onClick="addColor(':blue:','chat','text');">blue</a>
    Right now the above script when the hyper link named, "blue" is clicked, it writes ":blue:" to the screen. What I still need to do is close ":blue:" somehow and I want it to happen if "blue" is clicked. If "blue" gets clicked a second time, it should write "/:blue:" to the screen or something like that.

    I've tried this:
    Code:
    <script>function addColor(color, chat, text) {
    if (color == openTag) {
    	closeTag = "/";
    	color = closeTag+color;
    }
    var revisedMessage;
    var currentMessage = document.chat.elements[text].value;
    revisedMessage = currentMessage+color;
    document.chat.elements[text].value=revisedMessage;
    document.chat.elements[text].focus();
    var openTag = color;
    return;
    } 
    </script>
    but no love... can anyone help?

  • #2
    [Z]
    [Z] is offline
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    function addColor(color,chat,text){
    x=document.chat.elements[text];
    x.value=(x.value==color)? '/'+x.value : ñolor;
    x.focus();
    }

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    30
    Thanks
    2
    Thanked 0 Times in 0 Posts
    i don't quite understand how i'm supposed to incorporate that... would you mind elaborating a little?

  • #4
    [Z]
    [Z] is offline
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by thepip3r
    i don't quite understand how i'm supposed to incorporate that... would you mind elaborating a little?
    Replace your function...

  • #5
    New Coder
    Join Date
    Mar 2005
    Posts
    30
    Thanks
    2
    Thanked 0 Times in 0 Posts
    so the code you wrote above replaces my whole function? and i replace "x" in your function with everything preceding the "=" sign in my function right?


  •  

    Posting Permissions

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