简体   繁体   English

在单选按钮选择上显示表,然后将单选按钮值传递到表中的字段,选项添加更多,然后附加到现有表

[英]Show table on radio button select, then pass radio button value to field in table, option to add more, then append to existing table

First-time poster...please don't beat me up too bad. 第一次发布海报......请不要打扰我。 I'm not even sure how all of this works, but here goes. 我甚至不确定这一切是如何运作的,但是这里有。 I'm basically trying to recreate the form located here: http://yeticustomshop.com/get-quote I have the product selection showing and the table showing as of right now. 我基本上试图重新创建位于此处的表单:http: //yeticustomshop.com/get-quote我有产品选择显示,表格现在显示。

Needed user experience: 需要的用户体验:

  1. Select Product, product selection is replaced by table showing product selection name, checkbox, and quantity selector. 选择产品,产品选择将替换为显示产品选择名称,复选框和数量选择器的表格。
  2. Option to add another product. 选择添加其他产品。 If clicked, show product selection, then the process is repeated, adding new selections to table. 如果单击,显示产品选择,则重复该过程,向表中添加新选择。
  3. The ability to remove previously selected items. 删除以前选定的项目的功能。

Any takers? 任何接受者?

Here's a fiddle 这是一个小提琴

    // Get all the product radio buttons and loop them
var products = document.getElementsByName('product');
for (var i = products.length; i--;) {
    // add an event listener to do stuff when one of them is clicked
    products[i].addEventListener("click", function() {
        // get the value of the clicked button
        var cup = this.value;
        // put the value in the input box
        document.getElementById('yourSelection').value = cup;
        // hide the radio buttons and show the table
        document.getElementById("cupDesc").style.display = "block";
        document.getElementById("cupSelect").style.display = "none";
    });
}

Thanks to user " I wrestled a bear once " for the help! 感谢用户“ 我曾经摔过一只熊 ”的帮助!

Here you go. 干得好。 Please pay attention to the comments for the explanation. 请注意解释的注释。

// Get all the product radio buttons and loop them
var products = document.getElementsByName('product');
for (var i = products.length; i--;) {
    // add an event listener to do stuff when one of them is clicked
    products[i].addEventListener("click", function() {
        // get the value of the clicked button
        var cup = this.value;
        // put the value in the input box
        document.getElementById('yourSelection').value = cup;
        // hide the radio buttons and show the table
        document.getElementById("cupDesc").style.display = "block";
        document.getElementById("cupSelect").style.display = "none";
    });
}

Note that you should hide the selection table until the radio button is clicked with style='display:none' 请注意,在使用style='display:none'单击单选按钮之前,应隐藏选择表

Here's a fiddle 这是一个小提琴

Happy coding! 快乐的编码!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM