0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【JavaScript】入力値を監視して別のnodeに値を反映させる

Posted at
index.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="main.js" type="text/javascript"></script>
    <script src="sha512.js" type="text/javascript"></script>
</head>
<body>
    <div>
        <h2>Input data for replace hadh</h2>
        <input id="data" type="text" value=""/>
    </div>
    <div>
        <h2>result</h2>
        <textarea id="result" type="text" value="" style="width: 390px; height: 40px"></textarea>
    </div>
</body>
</html>

id="data"に入力された値を常に監視し、hash関数に入れた返り値をid="result"にリアルタイムで入れる。

setHash.js
window.onload = () => {
    const result = document.getElementById("result");
    const sethash = (it) => {
        const shaObj = new jsSHA("SHA-512", "TEXT");
        shaObj.update(it);
        result.innerText = shaObj.getHash("HEX");
    };
    document.getElementById("data").addEventListener("input" , (it) => {
        sethash(it.target.value);
    });
}

shaObjは以下のライブラリのsrc/sha512.jsをコピペして、HTML上で呼び出して使用する。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?