Home > Blockchain >  Copy input value after page loaded
Copy input value after page loaded

Time:08-20

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');

})

CodePudding user response:

document.addEventListener('DOMContentLoaded', function(){
  const InputValue = document.getElementById('gclid_field').value;
  const InputTarget = document.getElementById('gclid_form');
  InputTarget.value = InputValue;
})

CodePudding user response:

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;
});
  • Related