![](/img/trans.png)
[英]How to set the value of a form input field without ID using Javascript?
[英]how to in set javascript id in input value
我想將我的javascript ID插入到輸入值的位置。
如果我給Interest
名稱輸入value="100"
我如何獲得tc
命名表輸入value="75"
我的輸入表格
<tr>
<th>Loan Amount</th>
<th>INTEREST RATE %</th>
<tr>
<tbody>
<td><input disabled type="" name="tc" id="int_amount" class="formcontrol"value=""/></td>
<td><input type="number" name="Interest" id="input2" onkeyup="calculate();"/ class="form-control" value=""/></td>
</tr>
</tbody>
JavaScript的
var vatti = document.pricecal.Interest.value;
var Total = vatti -25;
if(vatti = null)
{
document.getElementById("int_amount").innerHTML = "Rs:"+" "+Total;
}
[want out put like this][1]
希望這對您有所幫助。
function calculate(interest){ var vatti = interest.value; if (vatti != '') { var Total = vatti - 25; document.getElementById("int_amount").value = Total; }else{ document.getElementById("int_amount").value = ''; } }
<table> <tbody> <tr> <td><input type="number" name="Interest" id="input2" onkeyup="calculate(this)" onchange="calculate(this)" class="form-control" value=""/></td> <td><input type="" name="tc" id="int_amount" class="formcontrol" value=""/></td> </tr> </tbody> </table>
設置<input>
元素的.value
而不是.innerHTML
document.getElementById("int_amount").value = "Rs:"+" "+Total;
HTML:
<tbody>
<tr>
<td><input type="number" name="Interest" id="input2" class="form-control" value=""/></td>
<td><input type="" name="tc" id="int_amount" class="formcontrol" value=""/></td>
</tr>
</tbody>
使用Javascript:
document.getElementById('input2').onkeyup = function() {
document.getElementById('int_amount').value = (this.value != '') ? 'Rs: ' + (parseInt(this.value)-25) : '';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.