There is such a calculator serjo96.imtqy.com/matrix. It is necessary to add functionality for adding and deleting rows, columns for selected radiobuttons, while another placeholder should be added with the report continued (see the link). As I understand it, first you need to add a radio check.

$(document).ready(function(){ var rad=document.getElementsByName('mtrx_sel'); for (var i=0;i<rad.length; i++) { if (rad[i].checked) { alert('Выбран '+i+' radiobutton'); } } }); 

Well, then in the if already write a click handler? Can anyone throw a sample code or suggest how to implement such things at all?

    2 answers 2

    If I understand correctly, then you need to hang an event handler on the elements. Here is an example.

     var controls = document.querySelector('.add_mtrx'); controls.addEventListener('click', handler); function handler(e) { var nodeName = e.target.nodeName; if (nodeName == 'BUTTON' || nodeName == 'INPUT') { console.log("Кликнули на ", e.target); } } 

    http://plnkr.co/edit/zYo7u0yHOh7BsGYiygxH?p=preview

    • Absolutely right, thank you so much) - Drop
    • But it is also necessary to take into account the selected radio button. The logic should be that when the radio is selected and after clicking on the add button, a row or column is added for one of the matrices. - Drop
    • So add a checked check to the desired radio button. - Chemaxa
    • Mmmm, that is, when you choose a radio, it puts the attribute checked and can it be checked once through if? - Drop
    • Yes, of course, the check attribute of the checkbox is set to true when clicked, but I don’t understand why to check it if it’s already known what item was clicked. In general, in this situation, there are two approaches or to hang up the handler on click or on change at checkbox. - Chemaxa

    Total here is the code that I needed)

     $('.add_str').click(function(){ if ($("#check_mtrx_a").prop("checked")){ $('.matrix_a tr:first').clone().appendTo('.matrix_a'); }else if($("#check_mtrx_b").prop("checked")) { $('.matrix_b tr:first').clone().appendTo('.matrix_b'); } });