Jetoox
Jetoox

Reputation: 1437

Get value from a textarea and place it in a new textarea with some added texts

  1. I have a textarea (txtar1) that will be filled up by a user with HTML codes.
  2. I have a 'generate' button;
  3. When the 'generate button is clicked, the value from txtar1 will be placed in a another textarea (txtar2). But with some added css code.

here's what I've done:

HTML:

<table>
<tr>
    <td valign="top"><label>Enter HTML Code : </label></td>
    <td><textarea id="htmlcode_txtarea"></textarea></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td><input type="button" name="" id="submit_btn" value="Generate" /></td>
</tr>
<tr id="new_html">
    <td><label>New HTML</label></td>
    <td><textarea id="new_htmlcode_txtarea"></textarea></td>
</tr>

javascript/jquery:

jQuery('#submit_btn').click(function(){ 
    var newVal = jQuery('#htmlcode_txtarea').attr('value');
    var addVal = "#af-form-1031686823 .af-element{float:left;}" + 
                "#af-form-1031686823 .af-clear{display:none}:" + 
                "#af-form-1031686823 .af-body input.text{width: 150px!important;margin0right:15px!important}" +
                "#af-form-1031686823 .buttonContainer{margin-top:-6px!important}";


    jQuery('#new_html').show();
    jQuery('#new_htmlcode_txtarea').attr('value',newVal);
});

What should i Do?

Upvotes: 0

Views: 559

Answers (1)

Pranay Rana
Pranay Rana

Reputation: 176896

easy wato achieve is make use of .val() function

$("#textarea2").val($("#textarea1").val() + "text to append ")

Upvotes: 5

Related Questions