Show element on radio button selection

后端 未结 3 1522
名媛妹妹
名媛妹妹 2021-01-15 15:05

I would like to show input text field on radio button selection in vanilla JavaScript.

What am I missing?

3条回答
  •  清歌不尽
    2021-01-15 15:35

    const form = document.querySelector("form");
    const size = form.elements.size;
    const total = form.elements.total;
    
    total.style.display = "none";
    
    for (var i = 0; i < size.length; i++) {
      size[i].onclick = function() {
        if (this.checked) {
          total.style.setProperty("display", "inherit");
          total.value = this.value;
        } else {
          total.style.setProperty("display", "none");
        }
      }
    }
    Choose Size

    Check this on Fiddle
    Hope this will be helpful.

提交回复
热议问题