Concatenating Strings

The Script

<script type="text/javascript">
// <![CDATA[

// create a variable to hold the text string
// you want to safe; when the page loads,
// it will be an empty string, but the 
// variable will exist in memory as long as 
// the page is in the browser
var currString = "";

function setTextArea(x)
{
  // add the value, x, passed from the "textin" field
  // to the variable;
  // + is the concatenation operator
  currString += currString;  // same as currString = currString + x;
  document.forms.myForm.textout.value = currString;
  document.forms.myForm.textin.value  = "";
  document.forms.myForm.textin.focus() 
  return true;
}
  
function doReset()
{
  currString = "";
  document.forms.myForm.textout.value = "";
  document.forms.myForm.textin.value  = "";
  return true;
}

// ]]>
</script>

The Form

<form action="javascript:;" method="post" id="myForm" onreset="currString=''">

<input type="text" name="textin" size="30" maxlength="32" value="" />

<textarea name="textout" cols="25" rows="10" value="">

</textarea>
<!-- onclick passes the value of field 'textin' to 
     the function set TextArea() -->
<input type="button" name="inputButton" value="Click here" 
onclick="setTextArea(textin.value);"> <input type="reset" name="Reset" value="Reset" >

</form>

Enter some text: