![](/img/trans.png)
[英]How to change the display value of two text boxes through the input value of another text box using javascript?
[英]Value radio boxes to input text with javascript
我嘗試從輸入框中的單選框中獲取值
<form action="test()">
<input type="radio" name="typ" id="typ" value="ws" onfocus="test()" checked> ws
<input type="radio" name="typ" id="typ2" value="nb" onfocus="test()"> nb
<input type="radio" name="typ" id="typ3" value="za" onfocus="test()"> za
<input type="radio" name="typ" id="typ4" value="zb" onfocus="test()"> zb
</form>
這是我的js:
<script type="text/javascript">
function test(){
document.getElementById('serverid').value=document.getElementById('typ').value;
}
function test(){
document.getElementById('serverid').value=document.getElementById('typ2').value;
}
function test(){
document.getElementById('serverid').value=document.getElementById('typ3').value;
}
function test(){
document.getElementById('serverid').value=document.getElementById('typ4').value;
}
</script>
這是我的輸入框,在這里我將獲得單選框的值:
<input type="text" style="background-color:#ffffff" size="15" name="ID" id="serverid">
但是,每次輸入框中都是zb,但是我會選擇:-)我希望您能理解我,我很抱歉我的英語。
我希望有一個人可以幫助我。
最后一個“測試”功能將隱藏所有先前的“測試”。 為它們命名不同,或使用onfocus =“ test('ws / nb / za / zb')”和
function test(rbId)
{
document.getElementById('serverid').value=document.getElementById(rbId).value;
}
您只需要一個功能:
function test() {
r = document.forms['theform'].elements['typ'];
for(var x = 0; x < r.length; x++) {
if(r[x].checked) {
radiovalue = r[x].value;
}
}
document.getElementById('serverid').value=radiovalue;
}
用表格名稱替換表格
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.