Good time! I have a form like that

<form> <table><tr><td>1</td><td><input type='radio' name='ityp' value='1'></td></tr></table> <table><tr><td>2</td><td><input type='radio' name='ityp' value='2'></td></tr></table> <table><tr><td>3</td><td><input type='radio' name='ityp' value='3'></td></tr></table> <input type='button' class='checker'> </form> 

I need that when I clicked on a button, the value of the radio that was pressed was recorded in the variable

tried a brute force to do something like this

 $(document).on("click", ".checker", function () { $(this).parent('form').children('table').children('tbody').children('tr').children('td:last-child').children("input[type='redio']").each(function(i, e){ //ну и тут собственно проверка нажат или нет может гдето ошибся в написани но это только для примера показываю }); }); 

the point is that it looks too cumbersome, can it be somehow easier to implement this design?

  • What a horror ... to use the ascent - Alexander
  • Yeah ... Something you got wet ... - Michael Vaysman

2 answers 2

 console.log($(this).closest('form').find("input[type='radio']:checked").val()); 
     var value = document.querySelector('input[name="ityp"]:checked').value;