Javascript无法从单选按钮和隐藏框读取值

时间:2019-02-21 18:58:20

标签: javascript html

当我选择单选按钮时,其他功能将启用文本框,并且我想从中读取值

function calculate() {
  var currency = parseFloat(0);
  var message = "";


  currency = document.getElementsByName("val")[0].value;

  message = ("You Have Entered Amount : " + currency);

  document.getElementById("result").innerHTML = message;
}
<td>
  <input type="radio" name="inputControl" value="1" onchange="setvisible(this.value)"> Euro
</td>

<td><input type="number" name="val" size="10" id="set1" style="visibility:hidden;">
</td>

1 个答案:

答案 0 :(得分:1)

删除[0] .value部分。试试这个

  

currency = document.getElementsByName(“ val”)