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 to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Putting a space in between two textbox outputs

    Hello,
    The code I pasted below was developed so that the user clicks one of the buttons under each heading (i.e. "Color" and "Size") and when the button is clicked, its inner text is copied and pasted into a textbox. However, if the user clicks, for example, "Red." and "Large.", the textbox displays "Red.Large." whereas I would like the textbox to display "Red. Large." (space in between the two inputs). I am sure this is something simple, but I can't figure this out and I am an absolute novice at all this coding business.
    Thank you very much.
    Code:
    <script language="JavaScript">
    function copy(ID_value)
    {
    var textToCopy = document.getElementById(ID_value).innerHTML;
    var whereToCopy = document.getElementById("text");
    whereToCopy.value += textToCopy;
    
    
    }
    </script>
    
    <div id="">
    Color
    <br />
    <BUTTON id="1"onClick="copy(1);">Blue.</BUTTON>
    <br />
    <BUTTON id="2"onClick="copy(2);">Red.</BUTTON>
    <br />
    <br />
    Size
    <br />
    <BUTTON id="3"onClick="copy(3);">Large.</BUTTON>
    <br />
    <BUTTON id="4"onClick="copy(4);">Small.</BUTTON>
    <br />
    
    <p />
    </div>      
    <TEXTAREA ID="text" readonly="readonly" style="height:50px; width:300px;">
    </TEXTAREA>

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,108
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Id values must start with a letter or a '_' character.

    Also to hard code a space in the HTML use &nbsp; as the space character

  • #3
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    Change the fifth line to:
    Code:
    whereToCopy.value += textToCopy + " ";

  • #4
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Nile View Post
    Change the fifth line to:
    Code:
    whereToCopy.value += textToCopy + " ";
    Thanks so much, that did the trick! If I wanted to insert a break instead of a space, how would I go about doing that? Writing Red.<br /> within the button text doesn't do anything. I assume this is also a javascript issue...

    Also, side note, I know these questions are really basic so I really appreciate anyone-who-tries-to-help-me's assistance.
    Last edited by Xeneize4; 06-30-2012 at 04:45 AM.

  • #5
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    Change the same line to:
    Code:
    whereToCopy.value += textToCopy + "\n";


  •  

    Posting Permissions

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