Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/javascript/form/getelementbyid/getelementbyid.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/javascript/form/getelementbyid/getelementbyid.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/javascript/form/getelementbyid/getelementbyid.html on line 2
フォームに値をセット | JavaScript | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/javascript/form/getelementbyid/getelementbyid.html on line 18

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/javascript/form/getelementbyid/getelementbyid.html on line 18
フォームに値をセット
フォームのテキストなどに動的に値をセットすることが出来ます。
まずフォームの部品にid属性を指定します。この属性はHTMLファイル内で一意でないといけません。
例えば以下のように指定します。

<input type="text" id="age">

このフォーム部品にアクセスするにはdocument.getElementById("age")を使用します。
getElementByIdの引数に操作したいフォーム部品のid属性を指定します。上記例の場合、ageです。
document.getElementById("age").valueとすると現在入力されている値を取得することが出来ます。
逆にこの値にセットすることによりフォーム部品に値をセットすることが出来ます。
以下、例です。



サンプルソース
<html>
<head>
<title></title>
<script type="text/javascript"><!--
    function a(){
        if(document.getElementById("SELECT").value == "WIN"){
            document.getElementById("text").value = "ウィンドウズ";
        }else if(document.getElementById("SELECT").value == "MAC"){
            document.getElementById("text").value = "マック";
        }else if(document.getElementById("SELECT").value == "UNIX"){
            document.getElementById("text").value = "ユニックス";
        }else{
            document.getElementById("text").value = "";
        }
    }
--></script>
</head>
<body>
<select name="OS" id="SELECT" onChange="a()">
<option value="">
<option value="WIN">Windows
<option value="MAC">Macintosh
<option value="UNIX">UNIX
</select>
<input type="text" id="text">
</body>
</html>

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/javascript/form/getelementbyid/getelementbyid.html on line 121

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/javascript/form/getelementbyid/getelementbyid.html on line 121

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/javascript/form/getelementbyid/getelementbyid.html on line 130

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/javascript/form/getelementbyid/getelementbyid.html on line 130