入力フィールドの値を設定する

JavaScriptでフォームの<input>テキストフィールドのデフォルト値を設定するには?

ソリューション

このような方法もあります。

document.getElementById("mytext").value = "My value";
解説 (9)

のような入力フィールドがある場合は

<input type='text' id='id1' />

のような入力フィールドがある場合、以下のようなコードをjavascriptに記述して、その値を次のように設定することができます。

document.getElementById('id1').value='text to be displayed' ; 
解説 (0)

お試しください。

document.getElementById("current").value = 12

// or

var current = document.getElementById("current");
current.value = 12
解説 (1)