I have two radio buttons. I would like to be able to get the value of the custom attribute "xmlvalue" of the checked radio button.
I have tried with the following script:
var userType = $("input[name=ctrl_CustomerType]:checked", this).attr('xmlvalue');
Markup:
<input type="radio" name="ctrl_CustomerType" id="ctrl_CustomerType_1" xmltag="CustomerType" xmlvalue="existingCustomer" checked="checked"> Yes
<br />
<input type="radio" name="ctrl_CustomerType" id="ctrl_CustomerType_2" xmltag="CustomerType" xmlvalue="newCustomer"> No
Fiddle here
-- But I keep getting "Undefined".
Any ideas?
Retrieving a custom attribute is a simple process. First, declare an instance of the attribute you want to retrieve. Then, use the Attribute. GetCustomAttribute method to initialize the new attribute to the value of the attribute you want to retrieve.
To retrieve a data-* attribute value as an unconverted string, use the attr() method. Since jQuery 1.6, dashes in data-* attribute names have been processed in alignment with the HTML dataset API. $( "div" ).
Use the target. dataset property to access data attributes from the event object in React. The dataset property provides read and write access to the custom data attributes of the element. The property returns a Map of strings which can be converted to an object.
Remove the context of your selector:
http://jsfiddle.net/NrQek/1/
var userType = $("input[name=ctrl_CustomerType]:checked").attr('xmlvalue');
alert("xmlvalue is: " + userType);
Your selector is wrong.
The input element is not children of a
element where you are clicking, so you cannot pass this
as a context to the selector
var userType = $("input[name=ctrl_CustomerType]:checked").attr('xmlvalue');
Demo: Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With