Reputation: 2785
I have the following form:
<form>
<input type="radio" name="group-stack" value="grouped" checked>grouped<br>
<input type="radio" name="group-stack" value="stacked">stacked
</form>
I want to get the currently selected radio button's value using d3.
The following attempts have been unsuccessful:
var val = d3.select('input[name="group-stack"]').checked; //undefined
var val = d3.select('input[name="group-stack"][checked]')[0][0].value //always 'grouped' regardless of which radio is selected
Upvotes: 10
Views: 8103
Reputation: 1767
I'm a little late to the party but, FWIW, this is the pure d3 way:
d3.select('input[name="group-stack"]:checked').property("value");
Upvotes: 11
Reputation: 353
Try this
d3.select('input[name="group-stack"]:checked').node().value
Upvotes: 15
Reputation: 2785
ah... got it
d3.select('input[name="group-stack"]:checked')[0][0].value
Upvotes: 0