skip to Main Content

How to get the text value from the SOURCE to the TARGET,after the page fully loaded?

SOURCE

<input id="gclid_field">

TARGET

<input id="gclid_form">

SCRIPT

window.addEventListener('load', function () {
document.getElementById('gclid_field').value
document.getElementById('gclid_form').setAttribute('value');

})

2

Answers


  1. document.addEventListener('DOMContentLoaded', function(){
      const InputValue = document.getElementById('gclid_field').value;
      const InputTarget = document.getElementById('gclid_form');
      InputTarget.value = InputValue;
    })
    
    Login or Signup to reply.
  2. better to store value first, then set value directly, not from setAttribute:

    window.addEventListener('load', () => {
        let inputValue = document.getElementById('gclid_field').value;
        document.getElementById('gclid_form').value = inputValue;
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search