根据输入字段更改文本并根据单选按钮禁用输入
我需要根据输入字段中输入的“年份”更改输入之前的文本, 更改“显示年份”时,禁用不必要的收入/资产字段。
<!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>
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/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
拉米怎么了? (ma kore?)
只需添加一个事件监听器,您可能想看看这个:
事件监听器
Whats up rami? (ma kore?)
Just add an event listener, you may want to take a look at this for instance:
Event Listeners