简体   繁体   English

根据输入字段更改文本并根据单选按钮禁用输入

[英]Changing text based on input fields and disable inputs based on radio buttons

I need to change the text before the input based on "year" entered on the input field, and when changing the "Years to Show", disable the unnecessary income/assets fields.我需要根据输入字段中输入的“年份”更改输入前的文本,并在更改“显示年份”时禁用不必要的收入/资产字段。

<!DOCTYPE html>
<html>
<head>
    <title>title</title>
    <script type="text/javascript">
        window.onload=function() {
            // On "year" change, validate it and cahnge the text befor the input fields.
            var year = document.getElementsByName("year");
            year.onclick=function() {
                this.year0_text.value = year[this.value];
                this.year1_text.value = year[this.value]+1;
                this.year2_text.value = year[this.value]+2;
            }

            // and on "years" change, disable the unnecessary income/assets fields.
        }
    </script>
</head>
<body>
    <form name="ar" action="." method="post">
        Year:<br />
        <input type="number" name="year" value="2011"><br />
        <br />
        Years to Show:<br />
        <input type="radio" name="years" value="0.5">first period (not full year)<br />
        <input type="radio" name="years" value="1">1 year<br />
        <input type="radio" name="years" value="2">2 years<br />
        <input type="radio" name="years" value="3">3 years<br />
        <br />
        Income:<br />
        <span class="year0_text">20XX-0</span> <input type="number" name="year0_income" value="0"><br />
        <span class="year1_text">20XX-1</span> <input type="number" name="year1_income" value="0"><br />
        <span class="year2_text">20XX-2</span> <input type="number" name="year2_income" value="0"><br />
        <br />
        Assets:<br />
        <span class="year0_text">20XX-0</span> <input type="number" name="year0_assets" value="0"><br />
        <span class="year1_text">20XX-1</span> <input type="number" name="year1_assets" value="0"><br />
        <span class="year2_text">20XX-2</span> <input type="number" name="year2_assets" value="0"><br />
    </form>
</body>
</html>

DEMO - http://jsfiddle.net/92GaE/2/演示 - http://jsfiddle.net/92GaE/2/

Whats up rami?拉米怎么了? (ma kore?) (妈妈?)

Just add an event listener, you may want to take a look at this for instance: Event Listeners只需添加一个事件侦听器,您可能想看看这个,例如: 事件侦听器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM