获取所选单选按钮的值到Firebase

时间:2016-07-04 21:53:32

标签: html firebase firebase-realtime-database

我有一张表格:

<form onsubmit="return send(this)">
<div>
    <input type="radio" id="1" name="check" value="check1" checked="checked">
    <input type="radio" id="2" name="check" value="check2">
    <input type="radio" id="3" name="check" value="check3">
  </div>
</form>

和js:

function send(formObj) {
  myFirebase.push({
     checked: formObj.check.value
  })
}

如何获取已检查的输入值并将其传递到对象键checked

1 个答案:

答案 0 :(得分:0)

var radiochecked = "";


for(i in formObj.check) {
  if(formObj.check[i].checked) {
    radiochecked = formObj.check[i].value;
  }
}

function send(formObj) {
  myFirebase.push({
  checked: radiochecked
}