I have the following html convertd to haml:
%input#insurance_isp_payment{ checked: "checked", type: "radio", name: "insurance_isp_payment", price: 27.22, value: "single"}
27,22 €
And now I want to get this price value from radio button which is checked. I tried something like that:
$('input[name=insurance_isp_payment]:checked').data("price")
But this not work. How can I solve this problem?
I have the following html convertd to haml:
%input#insurance_isp_payment{ checked: "checked", type: "radio", name: "insurance_isp_payment", price: 27.22, value: "single"}
27,22 €
And now I want to get this price value from radio button which is checked. I tried something like that:
$('input[name=insurance_isp_payment]:checked').data("price")
But this not work. How can I solve this problem?
Share Improve this question asked Sep 10, 2014 at 9:37 Mateusz UrbańskiMateusz Urbański 7,86216 gold badges74 silver badges141 bronze badges 02 Answers
Reset to default 16Try this : instead of data()
use attr()
to get the price value.
var price = $('input[name="insurance_isp_payment"]:checked').attr("price");
alert(price);
var price = $('input[name="insurance_isp_payment"]:checked').attr("data-price");
alert(price);
$('input[type=radio][name=insurance_isp_payment]').on('change', function() {
var price = $('input[name="insurance_isp_payment"]:checked').attr("data-price");
alert(price);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input data-checked="yes" type="radio" name="insurance_isp_payment" value="100" checked data-price="100" />Single
<input data-checked="no" type="radio" name="insurance_isp_payment" value="200" data-price="200"/>Double