Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disappearing statements in a textarea field

Status
Not open for further replies.

crystalb24

Programmer
Aug 31, 2004
75
US
I'm trying to alter the appearence of my textarea fields. What I want is for a statement to be visible in the textarea until the user begins to type there.

Here is the code for the textarea field -

Code:
<input type='hidden' name='mission'>
<TEXTAREA ROWS="10" COLS="65" name="section2atextarea" class="style20"></textarea>

and the javascript I'm using to populate the textarea from the checkboxes listed below it -

Code:
<script language="JavaScript">
function updateTextarea(cb)
{
 var taValue = document.formName.section2atextarea.value;
 if(cb.checked)
 {
  if(taValue != "")
   taValue += " ";

  taValue += cb.value; //APPENDS checked value to textarea
 }//end if
 else //checkbox is not checked
 {
  if(taValue.indexOf(cb.value) > -1)
  {
   taValue = taValue.replace(cb.value, "");//removes UNchecked value once
  }//end if
 }//end else

 taValue = taValue.replace(/\s+/g, " "); //reduces multiple spaces to single spaces
 if(taValue.indexOf(" ") == 0)
  taValue = taValue.substring(1);
 document.formName.section2atextarea.value = taValue;
}//end function
</script>

What changes do I need to make?

~Crystal
Click here ( for a free iPod
 
I don't quite know what all your code is about... but here is a very simple demonstration of what you have described:

Code:
<input name="username" type="text" value="Type your username here" onclick="if (this.value == 'Type your username here') this.value = '';" />

The text input shows a message ("Type your username here") and when the user clicks (or tabs) to edit, the text value is cleared.

Hope you can work from this.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top