Adding content from a Div into an input text field

Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
User avatar
JanMolendijk
Posts:282
Location:Holland Rotterdam

Adding content from a Div into an input text field

I still don`t understand how I can get the results from a div into a text input form field ?

Code: Select all

<div id="div2"> Content </div>
I want to place the result from #div2 into this type text:

Code: Select all

<input type="text" name="comment_content" rows="10" cols="50" id="comment_content" class="form-control" placeholder="Enter Comment" value="">

MarPlo Posts:186
To add content from a Div into an input field, for example when a button is pressed, you can use this JavaScript code:

Code: Select all

var div2 = document.getElementById('div2');
var comment_content = document.getElementById('comment_content');
var btn_add = document.getElementById('id_btn');
btn_add.addEventListener('click', (ev)=>{
  comment_content.value = div2.innerHTML;
});

JanMolendijk Posts:282
Thanks Chief for all your support....
My URL-extractor is working
in the comment-system

Similar Topics