Getting the value of a checked input

I am trying to get the values of cheked input boxes but I cannot…while one is 0 and the other is 1 I get 0 and 0…here is the code:

https://jsfiddle.net/fiddlehunt/n04odgff/20/

11 posts were split to a new topic: JSFiddle problems

This does it.

$('[type=radio]:checked').each((i, r) => console.log(r.value));

All I see is is the output pane

◯yes :radio_button:no
:radio_button:yes ◯no

That’'s all that’s supposed to be there for the test.

He’s trying to get the values of only the checked fields.

  $('.price_show').click(function (e) {
     var value = $(this).val();
      alert(value);
  });

ok this works…thanks.I would like to learn something else also.
Suppose that in the DOM there other also input boxes with different classes…in which case the selector must be more specific if we ought to choose the ones I have in the fiddle.

So my question is how the selector must be to choose only the ones in the fiddle-and again in the case there are more inputs in the DOM.

A common technique is to group the form fields using fieldsets, which you can use to selectively target the checkboxes that you require.

More complex solutions exist, but normally form design is a compromise between usability and ease of processing.

well, to find an element with a specific id, an id should be unique within a page, so you should use the #id selector when you want to find a single, unique element where as the jquery class selector finds elements with a specific class.

https://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-item-using-class-or-id/

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.