0

What I need is to duplicate the input 5 times,

And paste it on the textarea

How to do it please?

http://jsfiddle.net/ydr52kbx/30/

<div id="main">1234</div>
<text id="test"></textarea>

var copypass = $('#main').html();
for (var i = 1;i < 5;i++){
$('#test').append(copypass.clone());
}
1
  • When do you need to duplicate the input? On every keystroke? When a button is pressed? Something must trigger the duplication event. Commented Jun 7, 2018 at 6:32

3 Answers 3

1

You don't need to take clone if you are taking html. Also <text> should be changed to <textarea> Check this.

var copypass = $('#main').html();
for (var i = 1;i < 5;i++){
  $('#test').append(copypass);
}
Sign up to request clarification or add additional context in comments.

Comments

0

Use String#repeat and set the value to the textarea:

var copypass = $('#main').html();
$("#test").val(copypass.repeat(5));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main">1234</div>
<textarea id="test"></textarea>

1 Comment

Thank you, shorter and better!:)
0

try this one

first change <text to <textarea

var copypass = $('#main').html();
for (var i = 1; i < 5; i++) {
  $('#test').append(copypass); //remove clone
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main">1234</div>
<textarea id="test"></textarea>

1 Comment

Thank you, i will check it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.