tags:

views:

328

answers:

4

I have two input textareas, and the second one is hidden. Is it possible to automatically duplicate text typed in the first textarea to to the second?

So far I can think of 1) javascript, but not sure how to implement that. 2) do something with my forms in php:

$form['textarea1'] = array(
  '#type' => 'textarea',
  '#title' => 'title',
  '#rows' => 20,
  '#required' => TRUE,
);

and

$form['textarea2'] = array(
  '#type' => 'hidden',
  '#rows' => 20,
  '#required' => TRUE,
  '#default_value' => value from textarea 1?
);

btw, it's Drupal.

Thank you for any suggestions.

Update. The first form is being built by special module and it saves the data to it's own table instead of saving data to drupal system table (node_revisions). My module creates the second form to duplicate data to drupal system table.

A: 

Use javascript. Bind an onchange (Javascript) function to the source text area; that function grabs the contents of the source and puts it into the hidden text area.

If all you're ever doing is exactly duplicating information that's already there, you might reconsider why you're copying to the hidden area at all.

Matt Ball
A: 

Hi Alex

I know that you can do it with javascript

But why do you want to have two textfields with the same content... I am assuming that you are submitting a form? Can't you just post the content from one place and then when you capture the results use the same Request.Form(content) for both values?

Gerald Ferreira
Gerald, I answered your question above =)
+1  A: 

jQuery:

$('#textarea1').keyup(function() {
    $('#textarea2').val( $('#textarea1').val() );
});
Eevee
A: 
function postChange (psCopyFromId, psCopyToId)
{
   var copyFrom = document.getElementById(psCopyFromId);
   var copyTo = document.getElementById(psCopyToId);



   copyTo.value = copyFrom.value;
}



<textArea id="txt1" onChange="postChange(this.id, 'txt2');"></textArea>
<textArea id="txt2"></textArea>
Kevin