View Full Version : Putting a space in between two textbox outputs

06-30-2012, 05:22 AM
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. :o
Thank you very much.

<script language="JavaScript">
function copy(ID_value)
var textToCopy = document.getElementById(ID_value).innerHTML;
var whereToCopy = document.getElementById("text");
whereToCopy.value += textToCopy;


<div id="">
<br />
<BUTTON id="1"onClick="copy(1);">Blue.</BUTTON>
<br />
<BUTTON id="2"onClick="copy(2);">Red.</BUTTON>
<br />
<br />
<br />
<BUTTON id="3"onClick="copy(3);">Large.</BUTTON>
<br />
<BUTTON id="4"onClick="copy(4);">Small.</BUTTON>
<br />

<p />
<TEXTAREA ID="text" readonly="readonly" style="height:50px; width:300px;">

06-30-2012, 05:28 AM
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

06-30-2012, 05:29 AM
Change the fifth line to:

whereToCopy.value += textToCopy + " ";

06-30-2012, 05:36 AM
Change the fifth line to:

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.

06-30-2012, 06:26 AM
Change the same line to:

whereToCopy.value += textToCopy + "\n";