Get value of custom attribute
Asked Answered
C

2

38

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?

Compel answered 4/6, 2013 at 11:21 Comment(0)
J
56

Remove the context of your selector:

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

 var userType = $("input[name=ctrl_CustomerType]:checked").attr('xmlvalue');
        alert("xmlvalue is: " + userType);
Jeroboam answered 4/6, 2013 at 11:24 Comment(1)
I don't know what I was thinking. Thanks a lot. It works as intended.Compel
R
4

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

Regina answered 4/6, 2013 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.