Get value of custom attribute

Meek picture Meek · Jun 4, 2013 · Viewed 83.7k times · Source

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?

Answer

A. Wolff picture A. Wolff · Jun 4, 2013

Remove the context of your selector:

http://jsfiddle.net/NrQek/1/

 var userType = $("input[name=ctrl_CustomerType]:checked").attr('xmlvalue');
        alert("xmlvalue is: " + userType);