-3

I want to get value from below code.

<input name="button" type="button" class="button" onclick="refresh();" id="check_code" style="font-size:15pt; width:80px; height:25px; color:white; border:none;background-color: #845f5f;text-shadow: 1px -1px 0px black;box-shadow: inset 2px -1px 4px 0px black;" readonly="readonly" oncopy="return false" value="my value">

and paste the value got into below text field.

from this
<input type="text" name="verification_code" id="verification_code" style="width:150;">

to this
<input type="text" name="verification_code" id="verification_code" style="width:150;" value="my value">

This is the code I'm working with but it's not working for some reason.

// @name     autoinput
// @match    *://MY_SERVER/*
// @require  https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant    GM_addStyle
// ==/UserScript==
//- The @grant directive is needed to restore the proper sandbox.

function test()
{
    var element;
    element = document.getElementById("check_code").getAttribute("value");
    document.setElementById("verification_code").value = element;
}
Samantha1154
  • 117
  • 9
  • Sorry, I looked around other places but couldn't find why it's not working. Unless the code is not correct. I know it's not much of a code. It should be working, but why it isn't? – Samantha1154 Jan 14 '22 at 13:59

1 Answers1

0

document.setElementById() is not a function

var value = document.getElementById("source").value;
document.getElementById("dest").value = value;
<input type="text" id="source" value="value" />
<input type="text" id="dest" />
Tom
  • 4,972
  • 3
  • 10
  • 28
  • Thanks for your fast response. Your code wasn't working as well, but turns out problem was somewhere else in my setup. Fixed that issue and now my original code (with ```getElement```) works fine, yours working as well. Thanks for the clarification on ```document.setElementById()``` – Samantha1154 Jan 15 '22 at 04:08