Page 1 of 1

Adding content from a Div into an input text field

Posted: 07 Oct 2018, 14:11
by JanMolendijk
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="">

Adding content from a Div into an input text field

Posted: 07 Oct 2018, 17:46
by MarPlo
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;
});

Adding content from a Div into an input text field

Posted: 08 Oct 2018, 16:53
by JanMolendijk
Thanks Chief for all your support....
My URL-extractor is working
in the comment-system