テキストフィールドの内容を設定する

説明

テキストフィールドの内容を設定するにはinputタグのvalueプロパティに文字列などを入れます。

サンプルプログラム

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<link rel="stylesheet" href="css/main.css" type="text/css" media="all">
<script type="text/javascript" src="js/sample.js"></script>
</head>
<body>
<h1>テキストフィールドの内容を設定する</h1>
<form method="get" action="./regist.cgi" id="aForm">
<input type="text" name="currentTime" id="currentTime">
<input type="button" value="時間を設定する" id="setButton">
</form>
</body>
</html>

【スクリプト】
window.onload = function(){
document.getElementById("setButton").onclick = function(){
var dObj = new Date();
var time = dObj.getHours()+"時"+dObj.getMinutes()+"分"+dObj.getSeconds()+"秒";
document.getElementById("currentTime").value = time;
}
}
サンプルを実行
[戻る]