Hari Hari - 3 months ago 6
HTML Question

How can i pass content inside a textarea in a form to another form in same page without submit button

Here am working on a page were i need the content inside a textarea in a form tag to be passed to another set of form tag in the same page were i have no submit button to pass the content, please help me on this and pardon me if went wrong somewhere, thank you.

content.php

<?php
echo'
<form>
<div class="col-sm-12 form-group"><textarea rows="6" type="text" class="form-control" placeholder="Mail body" name="mail_body"></textarea></div>
//Without using submit button
</form>';
?>


pass_content.php

<?php
<form>
//pass the the content in above textarea in this form which is on the same page
</form>
?>

Answer

You can do this using jquery. Like this :

var $mail = $(".mail");

$(".email").keyup(function() {
    $mail.val( this.value );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<div class="col-sm-12 form-group"><textarea rows="6" type="text" class="form-control email" placeholder="Mail body" name="mail_body"></textarea></div>
</form>

<form>
<textarea rows="6" type="text" class="form-control mail" ></textarea>
</form>

UPDATE : As you want another field to be hidden.

you jquery code:

var $mail = $(".mail");

$(".email").keyup(function() {
   $mail.val( this.value );
});

and here is your html code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form> 
  <div class="col-sm-12 form-group">
    <textarea rows="6" type="text" class="form-control email" placeholder="Mail body" name="mail_body"></textarea>
  </div>
</form>

<form>
  <input type="hidden" class="mail" >
</form>
Comments